Forum Moderators: coopster

Message Too Old, No Replies

How to Sum up all the results of a query

         

Gian04

2:24 pm on Jul 17, 2007 (gmt 0)

10+ Year Member



I have a table "table1" with 2 fields "name", "amount". Now if I want to get all the records whose name='John' assuming I got 3 rows and I want to get the "amount" (total) of all the 3 rows, I believe there is a function to sum up without doing a loop, but I cant remember that. Please assist. Thanks

whoisgregg

2:47 pm on Jul 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This should do the trick. :)

SELECT `name`, SUM(`amount`) AS sum_amount FROM table1 WHERE `name`='John'