The SUM() function in SQL is used to calculate the sum of numeric columns. It can calculate sums based on specified columns, filters, aliases, grouping and aggregation of multiple columns, but only handles numeric values and ignores NULL values.
Usage of SUM() function in SQL
The SUM() function in SQL is used to calculate a set of The sum of the numbers. It is an aggregate function that operates on a set of rows or tables.
Syntax:
SUM(expression)
Where:
Usage:
SELECT SUM(salary) FROM employees;
SELECT SUM(salary) FROM employees WHERE department = 'Sales';
SELECT SUM(salary) AS total_salary FROM employees;
SELECT department, SUM(salary) AS total_salary FROM employees GROUP BY department;
SELECT SUM(salary) + SUM(bonus) AS total_compensation FROM employees;
Note:
The above is the detailed content of How to use sum function in sql. For more information, please follow other related articles on the PHP Chinese website!