[LeetCode/Sql] Nth Highest Salary

less than 1 minute read

문제정보

어떻게 풀까?

n번째로 많은 급여액을 구하는 함수를 작성하는 문제. Oracle함수인 DENSE_RANK()를 활용하였다.

문제풀이 (Oracle)

CREATE FUNCTION getNthHighestSalary(N IN NUMBER) RETURN NUMBER IS
result NUMBER;
BEGIN
	SELECT DISTINCT SALARY INTO RESULT
	FROM
	(SELECT DENSE_RANK() OVER (ORDER BY SALARY DESC) AS RANK, SALARY
	 FROM EMPLOYEE) T
	 WHERE T.RANK = N;
RETURN result;
END;

Leave a comment