My simple solution


  • 0
    I

    select d.Name,e3.Name,e3.Salary from (
    select distinct e1.Name,e1.DepartmentId,e1.Salary,e2.Rank from Employee e1,
    (
    select e1.Salary ,e1.DEPARTMENTID,COUNT(*) as Rank
    from (select distinct Salary,DepartmentId from Employee) e1,(select distinct Salary,DepartmentId from Employee) e2
    where e1.Salary <= e2.Salary and e1.DEPARTMENTID=e2.DEPARTMENTID
    Group by e1.Salary ,e1.DEPARTMENTID

    ) e2 where e1.Salary=e2.Salary and e1.DepartmentId=e2.DepartmentId
    ) e3,Department d
    where e3.rank<=3 and d.Id=e3.DepartmentId
    order by DepartmentId,Salary desc


Log in to reply
 

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