https://leetcode.cn/problems/the-winner-university/
主要考查if 函数的使用
IF(expr1,expr2,expr3)
SELECT IF(1>0, '真', '假')
FROM Table
SELECT
IF(1>0, IF(2>1, '真', '假'), '假')
FROM
Table
SELECT
CASE 1 WHEN 1 THEN '字段的值是1'
WHEN 2 THEN '字段的值是2'
ELSE '字段的值3' END
FROM Table
语法格式如下
IF search_condition THEN
RETURN()
ELSEIF search_condition THEN
RETURN()
ELSE
RETURN()
END IF
例如第N高薪水的完善
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
if N<0 then
RETURN (select min(Salary) from Employee);
else
SET N = N-1;
RETURN (
select ifnull((select distinct Salary from Employee order by Salary desc limit N,1),null) as NthHighestSalay );
end if;
END