My solution with variables, costs 1058 ms.

  • 0

    select Department,Employee,Salary
    from (Select Department, Employee,Salary,if(@prep=Department,if(@preS=Salary,@num:=@num-1,@num), if(@prep:=Department,@num:=1,@num:=1)) as rank,@num:=@num+1,@preS:=Salary from ( select as Department,e.Name as Employee,Salary from Employee e,Department d where e.DepartmentId = d.Id order by d.Name asc,e.Salary desc) k,(Select @prep:=null,@num:=1,@preS:=0) s) f
    where f.rank <= 3;

Log in to reply

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