SUM is an aggregate function which is used to calculate the sum or total of values in a particular column.
Syntax:
SELECT SUM (<Column Name>) from <Table Name>
Example:
We have a table with the following data in the table SALES.
In order to count the total amount ( sum of the total prices) can be obtained by using SUM function.
QUERY:
SELECT SUM(PRICE) FROM SALES
Result Set:
Result set contains sum (total amount) of all the values in column PRICE.
Note:
Syntax:
SELECT SUM (<Column Name>) from <Table Name>
Example:
We have a table with the following data in the table SALES.
ITEM | PRICE |
ABC | 99.05 |
ABC1 | 110.99 |
ABC2 | 70.89 |
ABC3 | 100.99 |
ABC4 | 55.89 |
In order to count the total amount ( sum of the total prices) can be obtained by using SUM function.
QUERY:
SELECT SUM(PRICE) FROM SALES
Result Set:
Result set contains sum (total amount) of all the values in column PRICE.
Note:
- Sum function can be applied only on int , float , decimal , money data types.
- SUM Function ignores the NULL values in the columns.