SQL SUM() Function
- Previous Page SQL min()
- Next Page SQL Group By
SUM() Function
The SUM function returns the total number of a numeric column (total amount).
SQL SUM() Syntax
SELECT SUM(column_name) FROM table_name
SQL SUM() Example
We have the following "Orders" table:
O_Id | OrderDate | OrderPrice | Customer |
---|---|---|---|
1 | 2008/12/29 | 1000 | Bush |
2 | 2008/11/23 | 1600 | Carter |
3 | 2008/10/05 | 700 | Bush |
4 | 2008/09/28 | 300 | Bush |
5 | 2008/08/06 | 2000 | Adams |
6 | 2008/07/21 | 100 | Carter |
Now, we want to find the total number of the "OrderPrice" field.
We use the following SQL statement:
SELECT SUM(OrderPrice) AS OrderTotal FROM Orders
The result set is similar to this:
OrderTotal |
---|
5700 |
- Previous Page SQL min()
- Next Page SQL Group By