Nth Highest Salary

  • 0
    set @row_number = 0;
    RETURN (
          # Write your MySQL query statement below.
        select ifnull(
          (select salary from 
            (select (@row_number := @row_number + 1) as num, salary
             from (select distinct salary from employee
                   order by salary desc
                  ) s1
            ) s2
            where num = n
        , null) as NthHighestSalary         

Log in to reply

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