group_id | user_id |
---|---|
1 | 1 |
1 | 2 |
1 | 3 |
2 | 2 |
3 | 1 |
3 | 3 |
groupsHash = groups.group(:group_id).order('count(user_id) desc').count(:user_id)
#=> {1=>3, 3=>2, 2=>1}
Get an array of group ids with 2 or more people from here
ids = groupsHash.filter_map{ |group| groupsHash[0].to_i if groupsHash[1] >= 2}
#=> [1, 3]
Recommended Posts