SQL SUM() Function

« Previous Chapter Next Chapter »

The SUM() Function

The SUM() function returns the total sum of a numeric column.

SQL SUM() Syntax

SELECT SUM(column_name) FROM table_name


SQL SUM() Example

We have the following "Purchases" table:

PU_ID OrderDate OrderPrice Customer
1 2015/11/12 1000 Karmen
2 2015/10/23 1600 Tendulkar
3 2015/09/02 700 Karmen
4 2015/09/03 300 Karmen
5 2015/08/30 2000 Jensen
6 2015/10/04 100 Tendulkar

Now we want to find the sum of all "OrderPrice" fields".

We use the following SQL statement:

SELECT SUM(OrderPrice) AS OrderTotal FROM Purchases

The result-set will look like this:

OrderTotal
5700

« Previous Chapter Next Chapter »

Have Any Suggestion? We Are Waiting To Hear from YOU!

Your Query was successfully sent!