Description
The SQL Aggregate Functions can be used to perform calculations on a set of values and return a single value, based on the type of functions.
- These can be used only with a SELECT statement.
- These perform calculations on a set of values and return a single value.
See aggregate functions for more details.
Let's look at an example SELECT statement with a SUM() function.
Table Date
employee_id | employee_name | gender | birth_date | hire_date | salary |
1 | Robin Hood | M | 1990-10-10 | 2010-10-15 | 25000 |
2 | Tony Blank | M | 1982-08-07 | 2010-01-05 | 89000 |
3 | Andrew Russel | M | 1998-05-04 | 2012-02-20 | 28000 |
4 | James Cooper | NULL | 2000-10-20 | 2015-05-10 | 45000 |
5 | Rose Cutler | F | 1985-08-08 | 2015-06-21 | 65000 |
Example
The below SELECT statement returns the sum of a set of values.
SELECT SUM(salary) FROM employees;
After successful execution, the output contains the below data.
SUM(salary) |
252000 |
Overall
We now understood the usage of the SUM() function on a SELECT statement.