#1.返回所有员工的部门名、部门号。
-- SELECT DISTINCT d.DNAME,e.DEPTNO FROM dept d,emp e where e.DEPTNO=d.DEPTNO;
#2.工资水平多于smith的员工信息。
-- SELECT * FROM emp e WHERE e.SAL>
-- (SELECT SAL FROM emp WHERE ENAME='smith');
#3.返回员工和所属经理的姓名。
-- SELECT e.ENAME mrgName,p.ENAME FROM emp e ,emp p where e.EMPNO=p.MGR;
#4.返回雇员的雇佣日期早于其经理雇佣日期的员工及其经理姓名
-- SELECT e.ENAME,p.ENAME FROM emp e ,emp p where e.EMPNO=p.MGR AND e.HIREDATE>p.HIREDATE;
#5.返回员工姓名及其所在的部门名称。
-- SELECT e.ENAME, d.DNAME deptName FROM emp e,dept d where e.DEPTNO=d.DEPTNO;
-- SELECT e.ENAME,d.DNAME FROM emp e LEFT JOIN dept d ON e.DEPTNO=d.DEPTNO;
#6.返回从事clerk工作的员工姓名和所在部门名称。
-- SELECT e.ENAME ,d.DNAME FROM emp e ,dept d where e.JOB='clerk' and e.DEPTNO=d.DEPTNO;
-- SELECT e.ENAME,d.DNAME FROM emp e LEFT JOIN dept d ON e.DEPTNO=d.DEPTNO WHERE e.JOB='CLERK';
#7.返回部门号及其本部门的最低工资。
-- SELECT DEPTNO,MIN(sal) FROM emp GROUP BY DEPTNO;
#8.返回销售部(sales)所有员工的姓名。
-- SELECT e.ENAME FROM emp e ,dept d WHERE e.DEPTNO =d.DEPTNO and d.DNAME='sales';
-- SELECT * FROM emp WHERE DEPTNO=(SELECT DEPTNO FROM dept WHERE dname='SALES');
#9.返回工资水平多于平均工资的员工。
-- SELECT * FROM emp e WHERE e.SAL>(SELECT AVG(SAL) FROM emp );
-- SELECT * FROM emp e,(SELECT avg(sal) avgSal FROM emp) ae WHERE e.SAL>ae.avgSal;
#10.返回与SCOTT从事相同工作的员工。
-- SELECT * FROM emp e where e.JOB=(SELECT JOB FROM emp WHERE ENAME='SCOTT') AND e.ENAME!='SCOTT';
#11.返回与30部门员工工资水平相同的员工姓名与工资。
-- SELECT sal FROM emp WHERE DEPTNO=30;
-- SELECT * FROM emp e where e.SAL in(SELECT DISTINCT SAL FROM emp WHERE DEPTNO=30) and e.DEPTNO<>30;
#12.返回工资高于30部门所有员工工资水平的员工信息。
-- SELECT * FROM emp e WHERE e.SAL>(SELECT MAX(SAL)FROM emp WHERE DEPTNO=30);
#13.返回部门号、部门名、部门所在位置及其每个部门的员工总数。
-- SELECT d.* ,COUNT(e.DEPTNO) FROM emp e,dept d WHERE e.DEPTNO=d.DEPTNO GROUP BY e.DEPTNO;
-- SELECT d.*,count(e.EMPNO) FROM dept d LEFT JOIN emp e ON d.DEPTNO=e.DEPTNO GROUP BY d.DEPTNO;
#14.返回员工的姓名、所在部门名及其工资。
-- SELECT e.ENAME,d.DNAME,e.SAL FROM emp e,dept d WHERE e.DEPTNO=d.DEPTNO;
#15.返回员工的详细信息。(包括部门名)
-- SELECT e.*,d.DNAME FROM emp e,dept d WHERE e.DEPTNO=d.DEPTNO;
#16.返回员工工作及其从事此工作的最低工资。
-- SELECT e.JOB,min(sal) FROM emp e GROUP BY e.JOB;
#17.计算出员工的年薪,并且以年薪排序。
-- SELECT ENAME,SAL*12 yearSal FROM emp ORDER BY yearSal;
#18.返回工资处于第四级别的员工的姓名。
-- SELECT e.ENAME FROM emp e ,salgrade s WHERE (e.SAL BETWEEN s.LOSAL AND s.HISAL) AND s.GRADE=4 ;
-- SELECT * FROM emp e,salgrade s WHERE e.SAL>=s.LOSAL AND e.SAL<=s.HISAL AND s.GRADE=4;
#19.返回工资为二等级的职员名字、部门所在地、和二等级的最低工资和最高工资
-- SELECT e.ENAME ,d.DNAME,d.LOC,s.LOSAL,s.HISAL
-- FROM emp e ,dept d,salgrade s
-- WHERE (e.SAL BETWEEN s.LOSAL AND s.HISAL) AND s.GRADE=2 AND e.DEPTNO=d.DEPTNO;
-- SELECT e.ENAME,d.LOC,s.LOSAL,s.HISAL FROM emp e
-- LEFT JOIN dept d on e.DEPTNO=d.DEPTNO
-- LEFT JOIN salgrade s on e.SAL>=s.LOSAL AND e.SAL<=s.HISAL
-- WHERE s.GRADE=2;
#20.工资等级多于smith的员工信息。
-- SELECT s.GRADE FROM emp e,salgrade s WHERE e.SAL>=s.LOSAL AND e.SAL<=s.HISAL AND e.ENAME='SMITH';
--
-- SELECT * FROM emp,salgrade
-- WHERE SAL>HISAL
-- and GRADE=(SELECT s.GRADE FROM emp e,salgrade s WHERE e.SAL>=s.LOSAL AND e.SAL<=s.HISAL AND e.ENAME='SMITH');