Sharing my solution without count distinct


  • 0

    The idea is to find out the 3rd max salary for each department and select all salary bigger than that.

    See below code.

    select d.name as Department, e.Name as Employee, e.Salary
    from employee e
    join department d on d.id = e.departmentid
    where e.salary >= ifnull((select distinct salary from employee e1 where > e1.departmentid = e.departmentid order by salary desc limit 2, 1), 0)
    order by d.name, e.salary


Log in to reply
 

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