How would I use Rails ActiveRecord to write a query similar to this?
select
table1.category as "Collection",
count(table4.category) as "Totals"
from
table1
group by table1.name
order by "Totals" desc
The goal here is to simply report on the number of categories in the table. I've tried a few permutations of .select()
and .count()
, but my newbness is too great. =/
Maybe it will help if I provide an expected results set. Something like:
| Collection | Totals |
| ---------- | ------ |
| category1 | 10 |
| category5 | 9 |
| category8 | 5 |
| category3 | 3 |