Im between cherry

LeetCode | MySQL | 177. Nth Highest Salary 본문

데이터분석/practice_query

LeetCode | MySQL | 177. Nth Highest Salary

meal 2020. 9. 9. 10:11

177. Nth Highest Salary

leetcode.com/problems/nth-highest-salary/

 

Nth Highest Salary - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

 

CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
    RETURN(
        SELECT IF(COUNT(sub.Salary) < N, NULL, MIN(sub.Salary))
        FROM(
            SELECT DISTINCT e.Salary
            FROM Employee AS e
            ORDER BY Salary DESC
            LIMIT N
            )sub
    );
END

 

Comments