176
要考虑为空和重复的情况,ifnull和distinct关键字的使用
select IFNULL((select distinct Salary from Employee order by Salary desc limit 1,1),null) as SecondHighestSalary
177
注意在sql语句中不能使用表达式N-1是不能使用的
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT BEGIN if N<=0 then RETURN(select min(Salary) from Employee); else set N = N-1; RETURN ( # Write your MySQL query statement below. select ifnull((select distinct Salary from Employee order by Salary desc limit N,1),null) as NthHighestSalay ); end if; END