SQL > SQL Functions > SUM Function

The SUM function is used to calculate the total for a column. The syntax is,

SELECT SUM("column_name")
FROM "table_name";

For example, if we want to get the sum of all sales from the following table,

Table Store_Information

Store_NameSalesTxn_Date
Los Angeles1500Jan-05-1999
San Diego250Jan-07-1999
Los Angeles300Jan-08-1999
Boston700Jan-08-1999

we would type in,

SELECT SUM(Sales) FROM Store_Information;

Result:

SUM(Sales)
2750

2750 represents the sum of all Sales entries: 1500 + 250 + 300 + 700.

Next: SQL ROUND Function




Copyright © 2014 1keydata.com   All Rights Reserved.   Privacy Policy