写法多多,只列其一:--1.列出至少有一个雇员的所有部门
select distinct b.dname
from emp a,dept b
where a.deptno=b.deptno;--4.列出入职日期早于其直接上级的所有雇员.
select a.ename
from emp a,emp b
where a.hiredate<b.hiredate and
a.mgr=b.empno ;
--5.列出部门名称和这些部门的雇员,///同时列出那些没有雇员的部门
select a.dname,b.ename
from dept a,emp b
where a.deptno=b.deptno
union
select dname,null
from dept
where deptno not in (select deptno from emp);
select distinct b.dname
from emp a,dept b
where a.deptno=b.deptno;--4.列出入职日期早于其直接上级的所有雇员.
select a.ename
from emp a,emp b
where a.hiredate<b.hiredate and
a.mgr=b.empno ;
--5.列出部门名称和这些部门的雇员,///同时列出那些没有雇员的部门
select a.dname,b.ename
from dept a,emp b
where a.deptno=b.deptno
union
select dname,null
from dept
where deptno not in (select deptno from emp);
select distinct b.dname
from emp a,dept b
where a.deptno=b.deptno;列出入职日期早于其直接上级的所有雇员.
好象不能回答
列出部门名称和这些部门的雇员
select a.dname,b.ename
from dept a,emp b
where a.deptno=b.deptno
同时列出那些没有雇员的部门select a.dname from dept where deptno not in(select deptno from emp )
或者可以
select a.dname from dept a ,emp b
where a.deptno(+)=b.deptno and a.deptno is null
select a.dname from dept a ,emp b
where a.deptno=b.deptno(+) and a.deptno is null
+号在右外部连接,它的意思是把b表中列全部检索出来,而不论该列数据是否在另外一个表中有匹配的数据,那么表示执行的查询按照内连接查询的执行形式,如果没有没有相应的匹配数据,则相应表中对应的内容是空值。由于加号防在了等号的右段,所以也就叫这种外连接查询称为外右连接查询。当然做你可以想到是怎么回事了吧~~!