Return the total sum of a numeric column.
The SUM() aggregate function calculates the total sum of values in a numeric column. It ignores NULL values in the calculation. SUM can be used with DISTINCT to sum only unique values. It is commonly used with GROUP BY to calculate totals for each group. SUM only works with numeric data types and returns NULL if there are no matching rows.
| Name | Description | Optional |
|---|---|---|
expression |
A numeric column or expression to sum. | No |
SELECT SUM(amount) FROM orders;
SELECT department, SUM(salary) FROM employees GROUP BY department;