My solution without fancy syntax

  • 3
    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

    select Department, Employee, Salary
    (Select Employee, Department, Salary, Rank() Over (Partition by Department order by Salary desc) AS E_Rank
    (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.