1:列出所有员工的姓名,部门名称,和工资
select a1.ename,a1.sal,a2.dname from emp a1,dept a2 where a1.deptno = a2.deptno;
2:列出所有部门的详细信息和部门人数
select a2.deptno,a2.dname,a2.loc,count(a1.empno) from emp a1,dept a2 where a1.deptno(+) = a2.deptno group by a2.deptno,a2.dname,a2.loc;
3:列出所有员工的年工资,所在部门名称,按年薪升序排列
select a1.sal*12 ,a2.dname from emp a1,dept a2 where a1.deptno = a2.deptno order by a1.sal*12;
4:查出每个员工的上级主管及所在部门名称,并要求这些主管的薪水超过3000
select employee.ename,boss.ename ,a1.dname from emp employee,emp boss,dept a1 where employee.mgr = boss.empno and boss.deptno = a1.deptno and boss.sal >3000;
5:求出部门名称中带’S’字符的部门员工的工资合计,部门人数
SELECT d.deptno,NVL(SUM(sal),0),COUNT(empno)FROM emp e,dept d WHERE e.deptno(+)=d.deptno AND d.dname LIKE '%S%' GROUP BY d.deptno ;
6:列出部门名称和这些部门的员工信息(数量,平均工资),同时列出那些没有员工的部门
select d.dname,avg(e.sal),count(e.empno) from emp e,dept d where e.deptno(+)=d.deptno group by d.dname;
7:列出在部门”SALES”工作的员工姓名,基本工资,雇用日期,部门名称,假定不知道销售部的部门编号
select a1.ename,a1.sal,a1.hiredate,a2.dname from emp a1,dept a2 where a1.deptno = a2.deptno and a2.dname = 'SALES';
8:列出公司各个工资等级雇员的数量,平均工资
select grade,count(*),avg(sal) from emp, salgrade where sal between losal and hisal group by grade;
9:列出薪水高于在部门30工作的所有员工的薪金的员工姓名和薪金,部门名称
select a1.ename,a1.sal,a2.dname from emp a1, dept a2 where a1.deptno = a2.deptno and sal > all(select sal from emp where deptno = 30);
10:列出受雇日期早于直接上级的所有员工的编号,姓名,部门名称,部门位置,部门人数
SELECT e.empno,e.ename,d.dname,d.loc,temp.count
FROM emp e,emp m,dept d,(
SELECT deptno dno, COUNT(empno) count
FROM emp
GROUP BY deptno) temp
WHERE e.mgr = m.empno(+) AND e.hiredate < m.hiredate
AND e.deptno = d.deptno
AND e.deptno = temp.dno;
11:列出所有“clerk”的姓名及其部门名称,部门人数,工资等级
SELECT e.ename , d.dname ,temp.count,s.grade
FROM emp e, dept d,(
SELECT deptno dno,COUNT(empno) count
FROM emp
GROUP BY deptno) temp,salgrade s
WHERE job='CLERK'
AND e.deptno = d.deptno
AND d.deptno = temp.dno
AND e.sal BETWEEN s.losal AND s.hisal;