16.列出各种工作的最低工资及从事此工作的雇员姓名
确定所需要的数据表:
emp表:最低工资,雇员名称
16.1 各种工作的最低工资
SELECT MIN(e.sal) minsal,e.job job FROM emp e GROUP BY e.job;
16.2 从事此工作的雇员姓名
SELECT e.ename ,temp.job,temp.minsal FROM emp e ,
(SELECT MIN(e.sal) minsal,e.job job FROM emp e GROUP BY e.job) temp
WHERE e.sal IN temp.minsal;
SELECT e.ename ,e.job,e.sal FROM emp e ,
(SELECT job,MIN(sal) min FROM emp GROUP BY job) temp
WHERE e.job=temp.job AND e.sal=temp.min;
17.列出各个部门的MANAGER的最低薪金、姓名、部门名称、部门人数
确定所需要的数据表:
emp表:姓名,各个部门的MANAGER薪金
emp表:统计部门人数
dept表:部门名称
确定已知的关联字段:
emp.deptno=dept.deptno
17.1 各个部门的MANAGER的最低薪金,姓名
SELECT deptno,MIN(sal) FROM emp WHERE job='MANAGER'
GROUP BY deptno;
SELECT e.ename,temp.dno,temp.min
FROM emp e,(SELECT deptno dno ,MIN(sal) min FROM emp WHERE job='MANAGER'
GROUP BY deptno) temp
WHERE e.deptno=temp.dno AND e.job='MANAGER' AND e.sal=temp.min;
SELECT e.ename,e.sal,d.dname
FROM emp e,(SELECT deptno dno ,MIN(sal) min FROM emp WHERE job='MANAGER'
GROUP BY deptno) temp,dept d
WHERE e.deptno=temp.dno AND e.job='MANAGER' AND e.sal=temp.min AND e.deptno=d.deptno ;
SELECT e.ename,e.sal,d.dname,res.count
FROM emp e,(SELECT deptno dno ,MIN(sal) min FROM emp WHERE job='MANAGER'
GROUP BY deptno) temp,dept d ,(SELECT COUNT(empno) count,deptno dno FROM emp GROUP BY deptno) res
WHERE e.deptno=temp.dno AND e.job='MANAGER' AND e.sal=temp.min AND e.deptno=d.deptno AND res.dno=d.deptno;
确定所需要的数据表:
emp表:年工资
dept表:部门名称
确定已知的关联字段:
emp.deptno = dept.deptno
SELECT e.ename,(NVL(e.sal,0)+NVL(e.comm,0))*12 salary,d.dname
FROM emp e ,dept d
WHERE e.deptno=d.deptno
ORDER BY salary desc;
19.查出某个员工的上级主管及所在的部门名称,并要求出这些主管中的薪水超过3000
确定所需要的数据表:
emp表:员工信息
emp表:上级主管,薪水
dpet表:部门名称
确定已知的关联字段:
emp1.mgr=emp2.empno
emp.deptno=dept.deptno
19.1 员工的上级主管以及所在部门名称
SELECT DISTINCT e.ename ,m.ename boss ,d.dname ,m.sal
FROM emp e,emp m ,dept d
WHERE e.mgr=m.empno AND m.deptno=d.deptno AND m.sal>3000;
20.求出部门名称中,带“S”字符的部门员工的工资合计、部门人数
确定所需要的数据表:
dept表: 部门名称
emp表:部门人数,工资合计
确定已知的关联字段:
emp.deptno=dept.deptno;
SELECT d.dname ,COUNT(e.empno),SUM(e.sal)
FROM emp e ,dept d
WHERE d.dname like '%S%'
GROUP BY d.dname;
emp表:任职日期,部门
SELECT e.ename ,e.sal ,NVL(e.sal,0)*(1+NVL(e.deptno,0)/100) sals
FROM emp e
WHERE MONTHS_BETWEEN(SYSDATE,hiredate)/12>30 OR TO_CHAR(e.hiredate,'yyyy')=87;