Skip to content

Commit e4cdfdd

Browse files
committedMar 17, 2015
177
1 parent 8d357c0 commit e4cdfdd

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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)`

0 commit comments

Comments
 (0)
Please sign in to comment.