码迷,mamicode.com
首页 > 数据库 > 详细

[LeetCode][SQL]Nth Highest Salary

时间:2015-06-09 00:53:38      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:

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

 

 

 

[LeetCode][SQL]Nth Highest Salary

标签:

原文地址:http://www.cnblogs.com/Liok3187/p/4562271.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!