Solution of 761ms


  • 0
    A

    Solution with group_concat() and find_in_set()

    select d.Name Department, e.Name Employee, e.Salary Salary from Employee e
    
    join (
    	select DepartmentId, group_concat(distinct Salary order by Salary desc) Salary_Group from Employee
    	group by DepartmentId ) g
    on 
    	e.DepartmentId = g.DepartmentId and
        find_in_set(e.Salary, g.Salary_Group) between 1 and 3
    
    join Department d
    on e.DepartmentId = d.Id
     
    order by e.DepartmentId, e.Salary desc
    

Log in to reply
 

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