Yannis
Yannis

Reputation: 922

How to add up the numbers in a column?

id  |  number
1   |    10
2   |    24
3   |    45
4   |    25
5   |    12

How can I get the sum of all numbers in the number column? Thanks

Upvotes: 1

Views: 1527

Answers (4)

Naftali
Naftali

Reputation: 146300

SELECT SUM(number) from table ...

try the code above.

Upvotes: 0

Yamikuronue
Yamikuronue

Reputation: 758

Should just be SELECT SUM(number) FROM table.

http://www.tizag.com/mysqlTutorial/mysqlsum.php has a nifty tutorial

Upvotes: 1

Marc B
Marc B

Reputation: 360652

select sum(number)
from yourtable

You'll want to look at MySQL's aggregate functions to see what all's available.

Upvotes: 0

Dan J
Dan J

Reputation: 16708

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. :)

Upvotes: 7

Related Questions