Count of Sums possibly using group_by
Posted
by Daniel Johnson
on Stack Overflow
See other posts from Stack Overflow
or by Daniel Johnson
Published on 2010-05-25T19:21:33Z
Indexed on
2010/05/25
19:31 UTC
Read the original article
Hit count: 132
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.
© Stack Overflow or respective owner