My solution without user-defined variables

  • 0

    select d.Name as Department, t.Name as Employee, t.Salary as Salary
    from Department d,
    (select e.DepartmentId, e.Name, e.Salary, (select count(*)
    from (select distinct Salary, DepartmentId from Employee)e1
    where e1.DepartmentId = e.DepartmentId and e1.Salary >= e.Salary) as RowNum
    from Employee e
    Order By e.Salary desc)t
    where d.Id = t.DepartmentId and t.RowNum <= 3

Log in to reply

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