#e.流程控制函数
-- (1)if(条件,t,f)如果条件成立返回t,否则返回f
列如:select if (1>2,'1大于2','1小于2')
查询雇员的薪资,如果雇员薪资>=3000,输出'高薪'否则'底薪'
select sal,if(sal>=3000,'高薪','底薪') from emp;
-- (2) ifnull(值1,值2) 如果值1不为空则返回值1,否则返回值2.
查询雇员的年薪
select sal*12 from emp;
select sal,comm,(sal+comm)*12 from emp;
select (sal+ifnull(comm,0))*12 from emp
-- (3) nullif(值1,值2)如果值1等于值2返回null否则返回值1
列如 select nullif(1,2),nullif(1,1)
-- (4) case 值
-- when 值1 then 结果1
-- when 值2 then 结果2
-- else 其他结果
-- end
(5) case
when 条件1 then 结果1
when 条件2 then 结果2
else 其他结果
end
列如:查询雇员薪资,如果雇员薪资>=3000,输出'高薪'否则'底薪'
select sal,case
when sal>=3000 then '高薪'
else '底薪'
end '薪资水平'
from emp