---求平均工资 SELECT AVG(sal) FROM emp; -----------大于平均工资 SELECT e.ename,e.job,e.sal FROM emp e WHERE e.sal>(SELECT AVG(sal) FROM emp) -------- --e领导编号=m雇员编号 --emp雇员表,dept部门表 SELECT e.ename 雇员姓名,e.job 雇员职位,e.sal 雇员工资, m.ename 领导姓名,m.job 领导职位, d.dname 部门名称 FROM emp e,emp m,dept d WHERE e.sal>( SELECT AVG(sal) FROM emp) AND e.mgr=m.empno(+) AND e.deptno=d.deptno -----------加FROM子查询语句,统计人数 SELECT e.ename 雇员姓名,e.job 雇员职位,e.sal 雇员工资, m.ename 领导姓名,m.job 领导职位, d.dname 部门名称,dtemp.count 部门人数 FROM emp e,emp m,dept d,( SELECT deptno dno,COUNT(empno) count FROM emp GROUP BY deptno) dtemp WHERE e.sal>( SELECT AVG(sal) FROM emp) AND e.mgr=m.empno(+) AND e.deptno=d.deptno AND dtemp.dno(+)=d.deptno ----加个工资表。工资等级 SELECT e.ename 雇员姓名,e.job 雇员职位,e.sal 雇员工资, m.ename 领导姓名,m.job 领导职位, d.dname 部门名称,dtemp.count 部门人数, s.grade 工资等级 FROM emp e,emp m,dept d,( SELECT deptno dno,COUNT(empno) count FROM emp GROUP BY deptno) dtemp,salgrade s WHERE e.sal>( SELECT AVG(sal) FROM emp) AND e.mgr=m.empno(+) AND e.deptno=d.deptno AND dtemp.dno(+)=d.deptno AND e.sal BETWEEN s.losal AND s.hisal --61m-----使用此工资等级的人数 SELECT s1.grade sg,COUNT(e1.empno) count FROM emp e1,salgrade s1 WHERE e1.sal BETWEEN s1.losal AND s1.hisal GROUP BY s1.grade --第七部--嵌入工资等级的人数,以s1.grade为分组 ---- SELECT s1.grade sg,COUNT(e1.empno) count FROM emp e1,salgrade s1 WHERE e1.sal BETWEEN s1.losal AND s1.hisal GROUP BY s1.grade; ----完成体 SELECT e.ename 雇员姓名,e.job 雇员职位,e.sal 雇员工资, m.ename 领导姓名,m.job 领导职位, d.dname 部门名称,dtemp.count 部门人数, s.grade 工资等级,stemp.count 等级人数 --m领导, FROM emp e,emp m,dept d,( SELECT deptno dno,COUNT(empno) count FROM emp GROUP BY deptno) dtemp, --dtemp 部门人数 salgrade s,( SELECT s1.grade sg,COUNT(e1.empno) count FROM emp e1,salgrade s1 WHERE e1.sal BETWEEN s1.losal AND s1.hisal GROUP BY s1.grade ) stemp --stemp 工资等级人数 WHERE e.sal>( SELECT AVG(sal) FROM emp) AND e.mgr=m.empno(+) AND e.deptno=d.deptno AND dtemp.dno(+)=d.deptno AND e.sal BETWEEN s.losal AND s.hisal AND s.grade=stemp.sg;