https://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
CASE WHEN
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
RETURN (
# Write your MySQL query statement below.
SELECT CASE WHEN COUNT(*) < N THEN NULL
ELSE MIN(SUB.SALARY) END
FROM (SELECT SALARY
FROM EMPLOYEE
ORDER BY SALARY DESC
LIMIT N) SUB
);
END
LIMIT
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
SET N = N - 1;
RETURN (
SELECT DISTINCT SALARY
FROM EMPLOYEE
ORDER BY SALARY DESC
LIMIT N, 1
);
END
'IT study > SQL' 카테고리의 다른 글
LeetCode : 185. Department Top Three Salaries (0) | 2021.10.22 |
---|---|
Leetcode : 180. Consecutive Numbers (0) | 2021.10.22 |
HackerRank : The Report (0) | 2021.10.22 |
HackerRank : Challenges (0) | 2021.10.22 |
LeetCode : 184. Department Highest Salary (0) | 2021.10.21 |