--判定函数
--decodedecode(condition,case1,express1,case2 , express2,….casen ,expressn,expressionm)
--查询部门信息,包含部门编号的中文标示
selectdeptno,
dname,
loc,
decode(deptno, 10, '十', 20, '二十', '30', '三十')
from dept;
--case whenthen else end
selectdeptno,
dname,
loc,
(casedeptno when 10 then '十' when 20 then '二十'
else '暂定' end) 中文编号
from dept;
--多行函数\聚合函数\组函数: 多条记录返回一个结果
--先 确定结果集|分组,然后对已经确定的数据进行运算
--count() sum() max() min() avg()
--注意 : 如果select后面一旦使用组函数,只能与组函数或者分组字段一起使用
-- 统计有员工存在的部门总数
select count(distinct deptno) from emp;
-- 统计20部门一共有多少人
select count(*) from emp where deptno = 20;
-- 计算本公司每个月一共要在工资上花费多少钱
select sum(sal) from emp;
-- 查询本公司的最高工资和最低工资
select max(sal),min(sal) from emp;
--查看30部门的最高工资和最低工资
select max(sal),min(sal) from emp where deptno = 30;
-- 请查询出 20部门的平均工资
select avg(sal) from emp where deptno=20;
-- 计算出所有员工的奖金总和
select sum(comm) from emp;
--null值不参与组函数计算
-- 统计有奖金的员工有几个
select count(comm) from emp;
--查询最高薪水的员工姓名,及薪水]
select ename,max(sal) from emp;
--分组 group ny 分组字
--select 数据 from 数据源where 行过滤条件 group by 分组字段..having组过滤信息order by 排序
--执行流程: from --> where --> group by -- having --> select--> order by
--分组之后,只能使用分组字段或者组函数