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 (select distinct Salary from Employee order by Salary desc limit N,1) 7 ); 8 END
使用子查询、distinct和limit来完成查询。