Custom Search

Saturday, August 23, 2008

SQL SUM Function

The SUM function returns the total sum of a column in a given selection. NULL values are not included in the calculation.
Syntax

SELECT SUM(column) FROM table

Example

This example returns the sum of all ages in the "person" table:

SELECT SUM(Age) FROM Persons

Result:

98

Example

This example returns the sum of ages for persons that are more than 20 years old:

SELECT SUM(Age) FROM Persons WHERE Age>20

Result:

79

No comments: