A simple solution use one join


  • 5
    Z

    select d.Name Department, e.Name Employee, Salary
    from Department d join Employee e on d.Id=e.DepartmentId
    where (Salary,d.id) in (select max(Salary),DepartmentId from Employee group by DepartmentId);


Log in to reply
 

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