流程控制函数 相当于java中的分支结构
select * from emp ;
select empno,ename,job, sal+comm from emp; -- 如果没有津贴,不发工资
select empno,ename,job ,sal+ifnull(comm,0) from emp; -- if comm is null sal+0,否则sal+COMM
-- 双分支结构 (二选一执行)
-- IF (sal>=3000) syso("high") else syso("low")
select empno,ename,job ,if(sal>=3000,'high','low') as grade from emp;
-- 双分支结构
select empno,ename,job,
case when sal>=3000 then 'high'
else 'low'
end
as grade
from emp;
-- 多分支结构
select empno,ename,job ,
case when sal>=3000 then 'high'
else case when sal>=2500 then 'mid'
else 'low'
end
end
as grade
from emp;