Nth Highest Salary


  • 0
    O

    CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
    BEGIN
    DECLARE M INT;
    SET M = IF(N>(select count(DISTINCT salary) from employee),0,N);
    RETURN (
    # Write your MySQL query statement below.
    select MIN(A.Salary) from (select * from employee GROUP BY Salary order by Salary desc limit M) A
    );
    END


Log in to reply
 

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