-- Calculate the number of employees on each Shift by Department
SELECT d.name as Dept, s.Name as Shift, COUNT(*) as EmployeeCount
FROM (HumanResources.Department d
INNER JOIN HumanResources.EmployeeDepartmentHistory e
ON d.DepartmentID = e.DepartmentID)
INNER JOIN HumanResources.Shift s
ON e.ShiftID = s.ShiftID
GROUP BY d.Name, s.Name
ORDER BY Dept, Shift