select e.ENAME,d.LOC
from emp e ,dept d
where e.DEPTNO =d.DEPTNO and (d.LOC ='DALLAS'or d.LOC ='CHICAGO') ;
第一个语句搜索结果有 SMITH ALLEN 等很多
ENAME |LOC |
------+-------+
SMITH |DALLAS |
ALLEN |CHICAGO|
WARD |CHICAGO|
JONES |DALLAS |
MARTIN|CHICAGO|
BLAKE |CHICAGO|
SCOTT |DALLAS |
TURNER|CHICAGO|
ADAMS |DALLAS |
JAMES |CHICAGO|
FORD |DALLAS |
c |DALLAS |
c |DALLAS |
b |DALLAS |
a |DALLAS |
jay_y |DALLAS |
张三 |DALLAS |
select e.ENAME,e.SAL ,s.LOSAL ,s.HISAL
from salgrade s ,emp e
where (e.SAL between s.losal and s.HISAL )and s.GRADE =3;
第二个搜索结果ALLEN TURNER 我希望从第一个语句的搜索结果中排除掉第二个语句中的搜索结果
ENAME |SAL |LOSAL|HISAL|
------+------+-----+-----+
ALLEN |1600.0| 1401| 2000|
TURNER|1500.0| 1401| 2000|
AI的回复
select e.ENAME,d.LOC
from emp e ,dept d
where e.DEPTNO =d.DEPTNO and (d.LOC ='DALLAS'or d.LOC ='CHICAGO')
and e.ENAME NOT IN (select e.ENAME
from salgrade s, emp e
where (e.SAL between s.LOSAL and s.HISAL) and s.GRADE = 3);
ENAME |LOC |
------+-------+
SMITH |DALLAS |
WARD |CHICAGO|
JONES |DALLAS |
MARTIN|CHICAGO|
BLAKE |CHICAGO|
SCOTT |DALLAS |
ADAMS |DALLAS |
JAMES |CHICAGO|
FORD |DALLAS |
c |DALLAS |
c |DALLAS |
b |DALLAS |
a |DALLAS |
jay_y |DALLAS |
张三 |DALLAS |