我是靠谱客的博主 懦弱白开水,这篇文章主要介绍leetcode177-Nth Highest Salary(找出第n大的数据),现在分享给大家,希望可以做个参考。

问题求解:

Write a SQL query to get the nth highest salary from the Employee table.

复制代码
1
2
3
4
5
6
7
+----+--------+ | 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.

问题求解:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
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内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(61)

评论列表共有 0 条评论

立即
投稿
返回
顶部