LeetCode 177. Nth Highest Salary
| 考点 | 难度 |
|---|---|
| Database | Medium |
题目
Write an SQL query to report the nth highest salary from the Employee table. If there is no nth highest salary, the query should report null.
思路
和选第二个salary一样,把offset改成n-1。
答案
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
DECLARE M INT;
SET M=N-1;
RETURN (
# Write your MySQL query statement below.
SELECT DISTINCT Salary FROM Employee ORDER BY Salary DESC LIMIT 1 OFFSET M
);
END
