首页 > 代码库 > oracle强化练习之分组函数
oracle强化练习之分组函数
1. 显示平均工资为>2000的职位
select job,avg(sal) from emp group by job having avg(sal)>2500;
2. 计算工资在2000以上,各种职位的平均工资大于3000的职位及平均工资
Select job,avg(sal) From emp where sal>2000 group by job having avg(sal)>3000;
3. 找每个部门的最高和最低的工资
Select deptno,max(sal),min(sal) From emp group by deptno;
4. 找每个部门中每种职位的最高和最低的工资
select deptno,max(sal),min(sal) from emp group by job,deptno;
select deptno,job,max(sal),min(sal) from emp where job is notnull group by job,deptno;
5. 显示出工作名称(job)中包含"MAN"的员工平均工资,最高工资,最低工资及工资的和
select avg(sal),max(sal),min(sal),sum(sal) from emp where job like ‘%MAN%‘;
6. 显示出20号部门的员工人数
select count(*) from emp where deptno=20;
7. 显示出平均工资大于2000的部门名称及平均工资
Select dname,avg(sal) From dept d,emp e where e.deptno=d.deptno group by dname having avg(sal)>2000;
8. 显示每个部门每种工作平均工资大于2500的部门及工作
Select deptno,job From emp group by deptno,job having avg(sal)>2500;
9. 显示出工作名称中包含"MAN",并且平均工资大于1000的工作名称及平均工资
Select job,avg(sal) From emp group by job having avg(sal)>1000 and job like’%MAN%’;
10. 显示出平均工资最高的的部门平均工资
11. 列出最低工资大于1500的各种工作
Select job From emp group by job having min(sal)>1500;
12. 列出各部门的员工数量及平均工作年限
Select deptno,count(*),avg((sysdate-hiredate)/365) From emp group by deptno;
Select deptno,avg((months_between(sysdate,hiredate))/12) from emp group by deptno;
oracle强化练习之分组函数