select sum(sal)/count(*) ,avg(sal) from emp;
两个结果是一样的
select sum(comm)/count(*) ,sum(comm)/count(comm),avg(comm) from emp;
二、三是一样的,一不一样
因为分组函数会自动滤空,可以嵌套滤空函数,避免滤空
比如count(comm),不会计算comm为null的行。
count(*)和count(nvl(comm,0))两个值是一样的
sum(),
avg(),
max(),
min(),
count(),求个数 count(distinct deptno)
分组数据:group by
多个列的分组
group by 后面可以加的d,e但是select有啊,a,b,c。且函数中没有,则by后必须后啊,abc
过滤分组数据:having 字句,把分组后满足条件的筛选出来
select deptno,avg(sal) from
emp group by deptno
having avg(sal)>2000;
where后不能使用多行函数
查询10号不能的平均工资
select deptno ,avg(sal)
from emp
group by deptno
having deptno=10;
select deptno,avg(sal)
from emp
where deptno=10
group by deptno;
//两个结果一样,但是此时where的效率更高
group by 语句的增强
break on null:取消报表格式
break on deptno skip 2;//相同的deptno只显示一次。每一跳两行