An understand solution with group by

  • 0
    # Write your MySQL query statement below
    select d.Name Department,e.Name Employee,tmp.Salary Salary
        (select DepartmentId,max(Salary) Salary
        from Employee
        group by DepartmentId) tmp 
        left join Employee e on tmp.Salary=e.Salary and tmp.DepartmentId=e.DepartmentId
        left join Department d on tmp.DepartmentId=d.Id
    where d.Name is not null

Log in to reply

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