Count of Sums possibly using group_by
- by Daniel Johnson
Say you have a user table and an order table which references user (user has_many orders) and contains an item count field.
How could you efficiently ask "how many uses ordered how many items?"
That is, to generate something along the lines of:
Number of users | sum of items
-------------------------------
5 users | 1 item
4 users | 5 items
1 user | 7 items
Thanks in advance.