开发者

How to add up the numbers in a column?

开发者 https://www.devze.com 2023-02-27 10:50 出处:网络
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?
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.

0

精彩评论

暂无评论...
验证码 换一张
取 消