你的位置:首页 > 信息动态 > 新闻中心
信息动态
联系我们

LeetCode知识点总结 - 177

2021/12/29 7:24:34

LeetCode 177. Nth Highest Salary

考点难度
DatabaseMedium
题目

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