Group by with ActiveRecord in Rails
- by Adnan
Hello,
I have a the following table with rows:
================================================================
id | name | group1 | group2 | group3 | group4 |
================================================================
1 | Bob | 1 | 0 | 0 | 1|
================================================================
2 | Eric| 0 | 1 | 0 | 1|
================================================================
3 | Muris | 1 | 0 | 1 | 1|
================================================================
4 | Angela | 0 | 0 | 0 | 1|
================================================================
What would be the most efficient way to get the list with ActiveRecords ordered by groups and show their count like this:
group1 (2)
group2 (1)
group3 (1)
group4 (4)
All help is appreciated.