Oracle(三)多行函数
--多行函数
select count(1) from emp;--查询总数量
select sum(sal) from emp;--工资总和
select max(sal) from emp;--最大工资
select min(sal) from emp;--最低工资
select avg(sal) from emp;--平均工资
---分组查询
--分组查询中,出现在group by 后面的原始列,才能出现在select后面
--没有出现在group by后面的列,想在select后面,必须加上聚合函数.
----查询每个部门的平均工资
select e.deptno,avg(e.sal)"平均工资"
from emp e
group by e.deptno;
---查询平均工资高于2000的部门信息
select e.deptno,avg(e.sal)"平均工资"
from emp e
group by e.deptno
having avg(e.sal)>2000;
---查询出每个部门工资高于800的员工的平均工资
select avg(e.sal)
from emp e
where e.sal>800
group by e.deptno;
--where是过滤分组前的数据,having是过滤分组后的数据.
--表现形式:where必须在group by 之前,having必须在group by 之后.