This will work and cleaner looking


  • 0
    L

    Re: Department Top Three Salaries

    select 
      t.Department,
      t.Employee,
      t.Salary
    from
    (
    select
      dense_rank() over (partition by a.DepartmentId order by a.salary desc) as salary_rnk,
      b.Name as Department,
      a.Name as Employee,
      a.Salary
    from employee a
         join department b
           on a.departmentid = b.id
    ) t
    where t.salary_rnk <= 3
    order by t.Department, t.salary_rnk;
    

Log in to reply
 

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