0

我正在尝试提供从未教过课程部分的讲师列表。

首先,我选择教授课程部分的教师列表

SELECT w.COURSE_NO
FROM INSTRUCTOR z , SECTION w
WHERE z.INSTRUCTOR_ID = w.INSTRUCTOR_ID

但是当提供一个从未教过它的列表时,我不会给我任何行或错误

SELECT SALUTATION, FIRST_NAME, LAST_NAME,ZIP
FROM INSTRUCTOR,SECTION
WHERE COURSE_NO NOT IN
(SELECT w.COURSE_NO
FROM INSTRUCTOR z , SECTION w
WHERE z.INSTRUCTOR_ID = w.INSTRUCTOR_ID)
ORDER BY SALUTATION, FIRST_NAME, LAST_NAME,ZIP;

我怎样才能提供从未教过的教师名单?

4

1 回答 1

1

我认为您忘记将连接谓词放在主体查询中:

SELECT SALUTATION, FIRST_NAME, LAST_NAME,ZIP
FROM INSTRUCTOR a,SECTION b 
WHERE a.INSTRUCTOR_ID = b.INSTRUCTOR_ID AND COURSE_NO NOT IN
    (SELECT w.COURSE_NO
    FROM INSTRUCTOR z , SECTION w
    WHERE z.INSTRUCTOR_ID = w.INSTRUCTOR_ID)
ORDER BY SALUTATION, FIRST_NAME, LAST_NAME,ZIP;

尝试使用 ANSI-92。

SELECT SALUTATION, FIRST_NAME, LAST_NAME,ZIP
FROM INSTRUCTOR a
INNER JOIN SECTION b ON a.INSTRUCTOR_ID = b.INSTRUCTOR_ID
WHERE COURSE_NO NOT IN
    (SELECT w.COURSE_NO
    FROM INSTRUCTOR z
    INNER JOIN SECTION w ON z.INSTRUCTOR_ID = w.INSTRUCTOR_ID
    ) 
ORDER BY SALUTATION, FIRST_NAME, LAST_NAME,ZIP;
于 2013-10-16T20:38:16.967 回答