having分组后二次筛选

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

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

运行结果:

 

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

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

运行结果:

 

也可以升降序:

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

 

 

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

方法1:

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

运行结果:

 

 方法2:

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

运行结果:

posted @ 2022-01-01 23:12  努力学爪哇  阅读(59)  评论(0编辑  收藏  举报