id | number
1 | 10
2 | 24
3 | 45
4 | 25
5 | 12
How can I get the sum of all numbers in the numb开发者_Go百科er
column?
Thanks
SELECT SUM(number) FROM table
Should do it.
If you only want to sum some of the numbers, or aggregate them by groups of IDs, or some other thing, then you'll need to learn about WHERE
or GROUP BY
clauses. :)
Should just be SELECT SUM(number) FROM table.
http://www.tizag.com/mysqlTutorial/mysqlsum.php has a nifty tutorial
select sum(number)
from yourtable
You'll want to look at MySQL's aggregate functions to see what all's available.
SELECT SUM(number) from table ...
try the code above.
精彩评论