思路和上题一样,需要注意的是函数中写法.limit中的N-1不可以直接写,需要另外定义。另外是需要注意定义完变量后加个;
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
declare M int;
set M = N -1;
RETURN (
select ifnull(
(select distinct(salary) from employee order by salary desc limit M,1),NULL
) as getNthHighestSalary
);
END
网友评论