177. 第N高的薪水
目录
1. 题目
2. 解题
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
RETURN (
# Write your MySQL query statement below.
select case when count(1)<N then null else min(t.Salary) end
from
(select distinct Salary from Employee order by Salary desc limit N) t
);
END
思路:获取limit N 来获取前n个,然后取最小
从中间表select时,中间表要命名别名t
一个没有通过的测试用例:
本题的思路,来源于博客:https://blog.csdn.net/ustbbsy/article/details/102690759