Write a SQL query to get the nth highest salary from the Employee table.
题意
编写一个 SQL 查询,获取 Employee 表中第 n 高的薪水(Salary)。
解题
思路:去重、排序、limit ,代码如下,已经在leetcode验证过了!CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
set n = n-1;
RETURN (
# Write your MySQL query statement below.
select distinct Salary
from Employee order by Salary desc
limit 1 offset n
);
END