Sum 函数求和组中所有行的值。如果省略 group by 子句,则对所有行求和。

select sum(salary) TotalSalary
from employees;
TotalSalary
2500
select DepartmentId, sum(salary) TotalSalary
from employees
group by DepartmentId;
DepartmentID TotalSalary
1 2000
2 500