流程函数
--if相关
select empno,ename,sal,if(sal>=2500,'高薪','底薪') as '薪资等级' from emp; -- if-else 双分支结构
select empno,ename,sal,comm,sal+ifnull(comm,0) from emp; -- 如果comm是null,那么取值为0 -- 单分支
-- case相关:
-- case等值判断
select empno,ename,job,
case job
when 'CLERK' then '店员'
when 'SALESMAN' then '销售'
when 'MANAGER' then '经理'
else '其他'
end '岗位',
sal from emp;
-- case区间判断:
select empno,ename,sal,
case
when sal<=1000 then 'A'
when sal<=2000 then 'B'
when sal<=3000 then 'C'
else 'D'
end '工资等级',
deptno from emp;
-- 6.其他函数
select database(),user(),version() from dual;
sql语句顺序
-- select --函数(avg,min,max)--from --where --group by --having --order by acs
select deptno,job,avg(sal)
from emp
group by deptno,job
having avg(sal) > 1200
order by deptno;
查询本部门最高工资的员工
--查询本部门最高工资的员工 order by 默认是升序
相关子查询
select * from emp e where sal = (select max(sal) from emp where deptno = e.deptno) order by deptno
标签:函数,sal,--,流程,when,emp,sql,deptno,select From: https://www.cnblogs.com/188221creat/p/17362980.html