SUM
suggest changeSUM adds the non-NULL values in the group. If GROUP BY is omitted, it sums the whole table. When every value is NULL, SUM returns NULL. The salaries below are the Employees sample: 1000, 400, 600, and 500.
select sum(salary) TotalSalary
from Employees;
TotalSalary|
—— |
2500 |
select DepartmentId, sum(salary) TotalSalary
from Employees
group by DepartmentId;
Department 1 is James, John, and Johnathon (1000 + 400 + 500). Department 2 is Michael (600).
| DepartmentId | TotalSalary| | —— | — | | 1 | 1900 | | 2 | 600 |
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents