Nth Highest Salary


  • 0
    W
    CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
    BEGIN
      RETURN (
          # Write your MySQL query statement below.
          select t.Salary
          from 
          (select e1.Salary,count(e2.Salary) rank
          from 
           (select Salary 
            from Employee
            group by Salary
            ) e1,
           (select Salary 
            from Employee
            group by Salary
            ) e2
          where e1.Salary <= e2.Salary
          group by e1.Salary
          ) t
          where t.rank = N
      );
    END
    

Log in to reply
 

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