和上一题一样,是更加 general的情况。
上一题:https://blog.csdn.net/laserljy123/article/details/123726837
考察点:
- LIMIT K, N == LIMIT N OFFSET K
- ORDER BY _ DESC
- 在SQL中定义函数
CREATE FUNCTION FUNC_NAME(param1 TYPE) RETURN RET_TYPE
BEGIN
DECLARE var VAR_TYPE;
SET var= ;
RETURN (
SQL statement
); -- this will return a list
END
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
DECLARE M INT;
SET M=N-1;
RETURN (
# Write your MySQL query statement below.
SELECT DISTINCT salary
FROM Employee
ORDER BY salary DESC
LIMIT 1 OFFSET M);
-- LIMIT M, 1);
END