Solution with explicit joins

  • 0
    SELECT AS Department, AS Employee, H.HighestSalary AS Salary
    FROM Employee E
        INNER JOIN Department D ON E.DepartmentId = D.Id
        INNER JOIN (SELECT DepartmentId, max(Salary) AS HighestSalary
                    FROM Employee
                    GROUP BY DepartmentId) H ON (E.DepartmentId = H.DepartmentId AND E.Salary = H.HighestSalary)

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.