Reputation: 245
Assume I have a table with the following data:
Name TransID Cost
---------------------------------------
Susan 1 10
Johnny 2 10
Johnny 3 9
Dave 4 10
I want to find a way to sum the Costs per name (assume the Names are unique) so that I get a table like this:
Name Cost
---------------------------------------
Susan 10
Johnny 19
Dave 10
Any help is appreciated.
Upvotes: 1
Views: 80
Reputation: 726849
This is relatively straightforward: you need to use a GROUP BY
clause in your query:
SELECT Name,SUM(Cost)
FROM MyTable
GROUP BY Name
Upvotes: 3