융무의 기술블로그
article thumbnail

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

1. Problem                                                                                                                      

2. Analysis                                                                                                                     

1.  먼저 N번째 높은 salary리를 찾는것이기 때문에 ORDERY BY를 이용해서 DESC 한다

 

2. OFFSET은 몇번째 ROW부터 출력할 것인지 묻는 함수이다 파이썬의 순서에 0,1,2를 생각하면 편할거같다.

 

3. Solution                                                                                                                    

<sql />
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT BEGIN SET N = N-1; RETURN ( # Write your MySQL query statement below. SELECT ( SELECT DISTINCT Salary FROM Employee ORDER BY Salary DESC LIMIT 1 OFFSET N ) ); END
profile

융무의 기술블로그

@융무

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!