having分组后二次筛选

1.统计各个岗位的平均工资

select deptno,avg(sal) from emp group by deptno having avg(sal)>2000;

运行结果:

having分组后二次筛选

 

 也可给avg(sal)取个名字,后面也用名字替换,运行结果一样。

select deptno,avg(sal) 平均工资 from emp group by deptno having 平均工资 >2000;

运行结果:

having分组后二次筛选

 

也可以升降序:

select deptno,avg(sal) 平均工资 from emp group by deptno having 平均工资 >2000 order by deptno desc;

 

having分组后二次筛选

 

2.统计各个岗位的平均工资,除了MANAGER

方法1:

select job,avg(sal) from emp where job != 'MANAGER' group by job ;

运行结果:

having分组后二次筛选

 

 方法2:

select job,avg(sal)from emp group by job having job != 'MANAGR';

运行结果:

having分组后二次筛选

上一篇:学习笔记 统计学生成绩


下一篇:[Unity3d]Unity系统自带函数生命周期以及相互关系