Simple solution using IFNULL, limit, offset


  • 0
    N
    CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
    BEGIN
    DECLARE X INT;
    SET X = N - 1;
      RETURN (
          select IFNULL((select distinct Salary from Employee order by Salary desc limit 1 offset X), NULL) as Salary
      );
    END
    

Log in to reply
 

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