Nth Highest Salary


  • 0
    P

    """
    CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
    BEGIN
    RETURN (
    # Write your MySQL query statement below.
    select c.salary from
    (select a.*, b.cnt
    from (select distinct salary from employee where salary is not NULL order by salary desc limit N) as a,
    (select count(distinct salary) as cnt from employee where salary is not NULL) as b
    ) as c
    where c.cnt>=N
    order by c.salary limit 1

    );
    END
    """


Log in to reply
 

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