SQL SUM Function

Saturday, December 10, 2011

tags SQL

The SQL SUM function returns the sum of the selected column, containing numeric values.

Employees Table

employeeIDemployeeNameage
1000John Smith40
1001Fred White27
1002Jane Scott53
1003Samuel Williams31


In this example, we want to find the sum of all the employees' ages in the employees table.


Syntax

SELECT SUM(column_name)
FROM Table


Example
SELECT SUM(age) as [Sum of Ages]
FROM employees


Results

Sum of Ages
151


The SQL SUM function is used to find the sum of the numeric values in a given column.

Did you find the page informational and useful? Share it using one of your favorite social sites.

Recommended Books & Training Resources

SQL Cookbook Head First SQL: Your Brain on SQL A Learners Guide