Okay, say that I have two columns, Person and Donation. With, for example, these as rows:
+++++++++++++++
Fred | $1000
Fred | $500
Bob | $1000
Bob | $7000
Sally| $500
Joe | $100
+++++++++++++++
How could I get it to display the following?
+++++++++++++++
Fred | $1500
Bob | $8000
Sally| $500
Joe | $100
+++++++++++++++
In other words, how could I group together all the donations under a certain person, and sum them up? What would be an example query that would accomplish this? (If at all possible, in a general way, that does not involve individually naming the people in the select/sum clause)
Thanks!
When you use a
GROUP BYclause with an aggregate function (likeSUM) the aggregate is calculated for each group.If you want to get more specific results, like those people with total donations more than $500, introduce a
HAVINGclause. This is sort of like aWHEREfor aggregate results:SQL Fiddle: http://sqlfiddle.com/#!2/2de84/1/0