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;