Nth Highest Salary


  • 0
    S

    Here is my solution

    CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
    BEGIN
      RETURN (
          # Write your MySQL query statement below.
          select  case when count(distinct Salary) < N then null else ( select Salary
          from (
          select distinct Salary
          from Employee
          order by Salary desc
          LIMIT N) a
          order by Salary
          LIMIT 1) end as Salary
          from Employee
      );
    END
    

Log in to reply
 

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