2072. 赢得比赛的大学
https://leetcode.cn/problems/the-winner-university/
主要考查if 函数的使用
mysql中if的方法
IF(expr1,expr2,expr3)
SELECT IF(1>0, '真', '假')
FROM Table
mysql中if多条件嵌套
SELECT
IF(1>0, IF(2>1, '真', '假'), '假')
FROM
Table
mysql中CASE WHEN
SELECT
CASE 1 WHEN 1 THEN '字段的值是1'
WHEN 2 THEN '字段的值是2'
ELSE '字段的值3' END
FROM Table
IF…ELSE…做为流程控制语句使用
语法格式如下
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