时间:2021-07-01 10:21:17 帮助过:3人阅读
按部门求出该部门平均工资,且平均工资取整数,采用截断
select deptno "部门编号",trunc(avg(sal),0) "部门平均工资" from emp group by deptno;
(继续)查询部门平均工资大于2000元的部门
select deptno "部门编号",trunc(avg(sal),0) "部门平均工资" from emp group by deptno having trunc(avg(sal),0) > 2000;
(继续)按部门平均工资降序排列
select deptno "部门编号",trunc(avg(sal),0) "部门平均工资" from emp group by deptno having trunc(avg(sal),0) > 2000 order by 2 desc;
除10号部门外,查询部门平均工资大于2000元的部门,方式一【having deptno<>10】
select deptno,avg(sal) from emp group by deptno having deptno<>10;
除10号部门外,查询部门平均工资大于2000元的部门,方式二【where deptno<>10】【推荐】
select deptno,avg(sal) from emp where deptno<>10 group by deptno;
显示部门平均工资的最大值
select max(avg(sal)) "部门平均工资的最大值" from emp group by deptno;
思考:显示部门平均工资的最大值和该部门编号?
select max(avg(sal)) "部门平均工资的最大值",deptno "部门编号"
from emp
group by deptno;
错误
group by 子句的细节: 1)在select子句中出现的非多行函数的所有列,【必须】出现在group by子句中 2)在group by子句中出现的所有列,【可出现、可不现】在select子句中 where和having的区别: where: 1)行过滤器 2)针对原始的记录 3)跟在from后面 4)where可省 5)先执行 having: 1)组过滤器 2)针对分组后的记录 3)跟在group by后面 4)having可省 5)后执行 oracle中综合语法: 1)select子句-----必须 2)from子句-------必须,不知写什么表了,就写dual 3)where子句------可选 4)group by子句---可选 5)having子句-----可选 6)order by 子句--可选,如果出现列名,别名,表达式,字段 |
Oracle系列:(12)多行函数
标签:oracle