概述
问题求解:
Write a SQL query to get the nth highest salary from the Employee table.
+----+--------+
| Id | Salary |
+----+--------+
| 1 | 100 |
| 2 | 200 |
| 3 | 300 |
+----+--------+
For example, given the above Employee table, the nth highest salary where n = 2 is 200. If there is no nth highest salary, then the query should return null.
问题求解:
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
declare n1 int;
set n1=N-1;
RETURN (
# Write your MySQL query statement below.
select Salary from
(select distinct Salary from Employee) t
order by Salary desc
limit n1,1
);
END
最后
以上就是懦弱白开水为你收集整理的leetcode177-Nth Highest Salary(找出第n大的数据)的全部内容,希望文章能够帮你解决leetcode177-Nth Highest Salary(找出第n大的数据)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复