Using Rails 3.0, i'm trying to do a count on number of times a each combination of column1 and column2 occur.
IE Column A has values A-Z and Column B has values 1-5, i want a count of A1, A2, etc.
Is there a way to either group by multiple columns or join the two columns and group of the result? In reading the documentation, it wasn't clear how to accomplish this.
You should be able to specify multiple attributes to group by. Something like:
MyClass.count(:all, :group => 'column1, column2')
I believe this is what you want to do: rails group by multiple columns. The calculations cannot handle the multiple column group by. You can also use find_by_sql.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With