[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

 

 

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。