Nth Highest Salary

来源:互联网 发布:淘宝模特拍摄的业务 编辑:程序博客网 时间:2024/06/05 00:10

Write a SQL query to get the nth highest salary from theEmployee table.
+----+--------+| Id | Salary |+----+--------+| 1  | 100    || 2  | 200    || 3  | 300    |+----+--------+

For example, given the above Employee table, the nth highest salary wheren = 2 is 200. If there is no nth highest salary, then the query should returnnull.

题意:找出表中工资第n高的

order by,limit 及变量的使用

CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INTBEGIN      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

0 0
原创粉丝点击