题意:找出表中第二高的工资
解法:倒着排序无重复的工资,并选出第二个数据,这里主要用limit 和 distinct。limit (偏移量(从0开始)),(取出多少行)
select (select distinct(Salary) from Employee order by Salary desc limit 1,1) as SecondHighestSalary
找出第N高的工资和这题题意相近
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
SET n=N-1;
RETURN (
# Write your MySQL query statement below.
select (select distinct (salary) from Employee order by salary desc limit n, 1)
);
END