I cannot get this to work. I need to first find the maximum sum of vacation and sick leave hours, then find which employees who have this value for their sum of vacation and sick leave hours. I can get the 168 max, but regardless of how I arrange things I cannot seem to then get just the employees who match this criteria – I just get a full list of all employees. Code below is last attempt, based on class direction. Thanks!
SELECT e.employeeID, SUM(e.vacationhours + e.sickleavehours) AS maxHours
FROM humanresources.employee e
WHERE EXISTS (
SELECT SUM(e.vacationhours + e.sickleavehours) AS totalhours
FROM humanresources.employee e)
GROUP BY e.employeeID
I’d go for this, without using specific SQL server syntax. I guess this should work in most DBMS: