[LeetCode][SQL]Nth Highest Salary

Nth Highest Salary

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.

https://leetcode.com/problems/nth-highest-salary/

 

 


 

 

题目是不难的,就是谁能告诉我为什么我本地的MySQL无论如何都是错的。

加上delimiter $$也并没有什么用...

还有第7行为毛不能加分号或者$$...

1 #drop function getNthHighestSalary$$
2 CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
3 BEGIN
4 DECLARE M INT;
5 SET M = N - 1;
6   RETURN (
7       select distinct Salary from Employee order by Salary desc limit M, 1
8   );
9 END

 

 

 

posted @ 2015-06-08 23:29  `Liok  阅读(253)  评论(0编辑  收藏  举报