练手001
1.列出至少有一个员工的所有部门 select dname from dept where deptno in (select deptno from emp); select dname from dept where deptno in (select deptno from emp group by deptno having count(EMPNO)>=1); select dname from dept a where exists (select null from emp b where a.DEPTNO=b.DEPTNO);
2.列出工资比smith工资多的员工信息 select * from emp where sal > (select sal from emp where ENAME='SMITH'); select * from emp a where exists(select null from emp b where a.sal>b.sal and b.ename='SMITH');
3.列出所有员工的姓名及其直接上级的姓名 select ENAME,(select ENAME from emp a where a.EMPNO=b.MGR) boss from emp b; select a.ename emp, b.ENAME boss from emp a, emp b where a.MGR=b.EMPNO(+);
4.列出受雇日期早于其直接上级的所有员工姓名 select a.ename from emp a where a.HIREDATE<(select HIREDATE from emp b where a.MGR=b.EMPNO);
5.列出部门名称和这些部门的员工信息 select dname,b.* from dept a, emp b where a.deptno=b.deptno;
6.列出所有‘clerk’员工的姓名及部门名称 select a.ename,b.dname from emp a, dept b where a.job='CLERK' and a.deptno=b.deptno;
7.列出最低工资大于1500的各种工作名 select distinct job from emp group by job having min(sal)>1500; select distinct job from emp a where sal>1500 and not exists(select null from emp b where a.job=b.job and a.sal>b.sal);