My solution without fancy syntax


  • 3
    S
    select d.Name, r.Name, r.Salary 
    from (
      select DepartmentId, Name, Salary,(
        select count(*)+1 from (
          select distinct salary, DepartmentId from Employee 
          ) as uniq
         where DepartmentId = e.DepartmentId and Salary > e.Salary   
        ) as rank
      from Employee e
      ) as r, Department d
    where r.DepartmentId = d.Id and r.rank <= 3

  • 0
    P

    select Department, Employee, Salary
    from
    (Select Employee, Department, Salary, Rank() Over (Partition by Department order by Salary desc) AS E_Rank
    from
    (select A.Name AS Employee, B.Name AS Department, Salary
    From Employee A INNER JOIN Department B
    ON A.DepartmentId=B.ID)C)D
    where E_Rank<=3;

    This code works fine in MySQL in my laptop but not in leetcode. in leetcode throws a runtime exception.


Log in to reply
 

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