Ugly code better performance, 786 ms


  • 0
    L
    select Salary from (
        select salary from (
            (
              select distinct Salary from Employee order by Salary desc limit N)
              union all
              (select null)
            ) r order by salary desc limit N
        ) s
        order by salary
        limit 1

  • 0
    F

    Select the Nth Highest Salary
    CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
    BEGIN
    set N=N-1;
    RETURN (
    # Write your MySQL query statement below.
    SELECT (SELECT DISTINCT Salary FROM Employee
    ORDER BY Salary DESC LIMIT N,1
    ));
    END


Log in to reply
 

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