首页 > 数据库技术 > 详细

【SQL】177. Nth Highest Salary

时间:2017-03-03 01:13:37      阅读:193      评论:0      收藏:0      [点我收藏+]

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.

 1 CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
 2 BEGIN
 3   set N=N-1;
 4   RETURN (
 5       # Write your MySQL query statement below.
 6       select distinct Salary
 7       from Employee
 8       order by Salary desc
 9       limit N,1
10   );
11 END

 

【SQL】177. Nth Highest Salary

原文:http://www.cnblogs.com/fcyworld/p/6493249.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!