My solution with self join


  • 0
    H

    select t4.Name as Department, t3.name as Employee,t3.Salary from
    (select t1.name, t1.salary, t1.departmentid, count(*) as rank from Employee t1,
    (select distinct salary,departmentid from Employee) t2
    where t1.departmentid=t2.departmentid and t1.salary<=t2.salary group by t1.name,t1.salary,t1.departmentid order by departmentid) as t3
    join Department t4
    on t3.departmentid=t4.id and t3.rank<=3
    order by t4.Name;


Log in to reply
 

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