Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- RLIKE
- full request
- L2정규화
- coding
- AWS
- early stopping
- CSS
- 클라우드컴퓨팅
- mysql
- 편향-분산 교환
- L1정규화
- HTML
- branch
- PYTHON
- 선형 모형
- 버전충돌
- 온라인협업
- sql
- merge
- 코딩공부
- 깃헙협업
- 교차 엔트로피
- programmers
- hackerrank
- Git
- github
- conflict
- leetcode
- window function
- elastic net
Archives
- Today
- Total
Im between cherry
LeetCode | MySQL | 177. Nth Highest Salary 본문
177. Nth Highest Salary
https://leetcode.com/problems/nth-highest-salary/
--CASE로 풀기
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
RETURN (
# Write your MySQL query statement below.
SELECT CASE WHEN COUNT(sub.Salary) < N THEN NULL
ELSE MIN(sub.Salary)
END
FROM(
SELECT DISTINCT Salary
FROM Employee
ORDER BY Salary DESC
LIMIT N
)sub
);
END
-- if function 쓰기
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
RETURN (
SELECT IF(COUNT(sub.Salary) < N, NULL, MIN(sub.Salary))
FROM(
SELECT DISTINCT Salary
FROM Employee
ORDER BY Salary DESC
LIMIT N
)sub
);
END
-- LIMIT 심화 풀이법
CREATE FUNCTION getNthHighestSalary(N INT)
RETURNS INT
BEGIN
--DECLARE A INT;
SET N = N-1;
RETURN (
SELECT DISTINCT Salary
FROM Employee
ORDER BY Salary DESC
LIMIT 1 OFFSET N
);
END
'데이터분석 > practice_query' 카테고리의 다른 글
LeetCode | MySQL | 184. Department Highest Salary (0) | 2020.09.08 |
---|---|
LeetCode | MySQL | 180. Consecutive Numbers (0) | 2020.09.08 |
Programmers | MySQL | DATETIME에서 DATE로 형 변환 (0) | 2020.09.02 |
Programmers | MySQL | 오랜 기간 보호한 동물(2) (0) | 2020.09.02 |
Programmers | MySQL | 중성화 여부 파악하기 (0) | 2020.09.02 |
Comments