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

题目3:MySQL----------Nth Highest Salary

时间:2015-05-23 06:31:23      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:sql   database   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.

题目解答:

CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
DECLARE M INT;
SET M=N-1;
  RETURN (
      # Write your MySQL query statement below.
      SELECT DISTINCT Salary FROM Employee ORDER BY Salary DESC LIMIT M, 1
  );
END






题目3:MySQL----------Nth Highest Salary

标签:sql   database   nth highest salary   

原文地址:http://blog.csdn.net/chenxun_2010/article/details/45928229

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