Forum Moderators: coopster

Message Too Old, No Replies

MySQL: Adding the total of all rows

how to get the sum of a column

         

erikcw

2:57 pm on Oct 2, 2005 (gmt 0)

10+ Year Member



Hi all,

I'm trying to figure out how to do some math in MySQL. I have a table with a column of intergers. I need to find the sum.

2
2
3
4
+=11

I just can't figure out how to perform the SELECT.

SELECT sum(numbers) WHERE column2 = 'abc';

Can anyone point me in the right direction?

Thanks!

py9jmas

3:09 pm on Oct 2, 2005 (gmt 0)

10+ Year Member



SELECT SUM(column_name) FROM table_name;

or
SELECT SUM(column_name) FROM table_name WHERE other_column='whatever';

should be enough.

erikcw

3:12 pm on Oct 2, 2005 (gmt 0)

10+ Year Member



That did it! Thanks so much!