-- 控制流函数
-- if
select if(5>3,'大于','小于');
use mydb3;
select *,if(score>=85,'优秀','及格') flag from score;
-- ifnull
select ifnull(5,0);
use test1;
select *,ifnull(comm,0) comm_flag from emp;
-- 是null为1,不是null为0
select isnull(5);
select isnull(null);
-- nullif,相同为null,不相同返回第一个
select nullif(12,12);
select nullif(11,12);
-- case when
select
case 5
when 1 then '你好'
when 2 then 'hello'
when 5 then '正确'
else '其他'
end;
select
case
when 2>1 then '你好'
when 2>3 then 'hello'
when 3>2 then '正确'
else '其他'
end;#结果为你好,有一句话成立就不执行下面的了
MYSQL 寒假自学 2022 十二 (六)
最新推荐文章于 2024-10-09 18:19:09 发布