File tree 2 files changed +27
-0
lines changed
solutions/177.Nth_Highest_Salary
2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change
1
+ CREATE FUNCTION getNthHighestSalary (N INT ) RETURNS INT
2
+ BEGIN
3
+ DECLARE M INT ;
4
+ SET M= N- 1 ;
5
+ RETURN (
6
+ # Write your MySQL query statement below.
7
+ SELECT DISTINCT Salary
8
+ FROM Employee
9
+ ORDER BY Salary DESC
10
+ LIMIT M, 1
11
+ );
12
+ END
Original file line number Diff line number Diff line change
1
+ ## 177. Nth Highest Salary (Medium)
2
+
3
+ ### ** 链接** :
4
+ 题目:https://leetcode.com/problems/nth-highest-salary/
5
+ 代码(github):https://github.com/illuz/leetcode
6
+
7
+ ### ** 题意** :
8
+ 求第 N 大的工资。
9
+
10
+ ### ** 分析** :
11
+
12
+ [ 176.Second_Highest_Salary] ( https://github.com/illuz/leetcode/tree/master/solutions/176.Second_Highest_Salary ) 的变形题。
13
+ 算法题做多了,我一下就写了个递归,然后被告知 SQL 不能用递归。
14
+ 可以用 ` ORDER BY ` 排序,再用 ` LIMIT ` 返回第 N 大值。
15
+ 题目要求返回值是 INT 或 NULL,所以我们可以用 ` DISTINCT ` 或用 ` IFNULL(..., NULL) ` 。
You can’t perform that action at this time.
0 commit comments