自定义函数
DELIMITER $$
DROP FUNCTION IF EXISTS getNthHighestSalary$$
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
SET N = N - 1;
RETURN (
# Write your MySQL query statement below.
-- 第n高的薪水,来源于leetcode
SELECT
( SELECT DISTINCT salary FROM employee ORDER BY salary DESC
LIMIT 1 OFFSET n ) AS getNthHighestSalary
);
END
- DELIMITER $$ 自定义结束符,防止语句中的分号导致程序结束
- 如果该函数已存在,就删除它
- BEGIN与RETURN之间声明变量