设为首页 加入收藏

TOP

题目3:MySQL----------NthHighestSalary
2015-07-24 12:15:41 来源: 作者: 【 】 浏览:57
Tags:题目 MySQL----------NthHighestSalary

?

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


?

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇说说FoundationDB 下一篇题目8:MySQL----------Duplicate..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: