NTH HIGHEST SALARY


  • 0
    T

    CREATE FUNCTION getNthHighestSalary(Nth INT) RETURNS INT
    BEGIN
    DECLARE M INT;
    SET M=Nth-1;
    RETURN (
    # Write your MySQL query statement below.
    SELECT
    IFNULL(
    (SELECT DISTINCT Salary
    FROM Employee
    ORDER BY Salary DESC
    LIMIT 1 OFFSET M),
    NULL) AS SecondHighestSalary
    );
    END


  • 0
    P

    CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
    BEGIN
    RETURN (
    # Write your MySQL query statement below.
    select
    IFNULL(
    (select a.salary
    from (select
    e.salary
    , @curRank := @curRank + 1 AS rank
    from (select distinct salary from Employee order by salary desc limit N) e, (SELECT @curRank := 0) r) a
    where a.rank=N), NULL)
    );
    END


Log in to reply
 

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