The SQL SUM function returns the total value within a table or group. In this section we’ll use the HumanResource.Employee table for our examples: 

Using the data above, SUM calculates the total SickLeaveHours for all employees:

SELECT SUM(sickleavehours) SUMSickLeaveHours FROM HumanResources.Employee
SELECT SUM(sickleavehours) SUMSickLeaveHours 
  FROM HumanResources.Employee

When used with GROUP BY, SUM totals the values within a group. You can see this in this query showing the maximum SickLeaveHours by JobTitle:

SELECT JobTitle , SUM(sickleavehours) AS SUMSickLeaveHours FROM HumanResources.Employee GROUP BY JobTitle ORDER BY JobTitle;
SELECT JobTitle 
 , SUM(sickleavehours) AS SUMSickLeaveHours 
FROM HumanResources.Employee 
GROUP BY JobTitle 
ORDER BY JobTitle;

Additional SQL SUM Resources  

To learn more, check out these useful resources: 

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
>