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