我試圖提供一個包含採用系統分析和項目管理課程的學生的列表。子查詢 - 列出兩個課程
當我單獨選擇'系統分析'或'項目管理'時,它會給我結果,但不是我所需要的。我需要參加兩門課程的學生。
SELECT FIRST_NAME, LAST_NAME, PHONE
FROM STUDENT d,ENROLLMENT f,SECTION g,COURSE h
WHERE d.STUDENT_ID = f.STUDENT_ID AND f.SECTION_ID = g.SECTION_ID AND g.COURSE_NO = h.COURSE_NO
AND h.DESCRIPTION = 'Systems Analysis' AND h.DESCRIPTION = 'Project Management'
AND DESCRIPTION NOT IN
(SELECT m.DESCRIPTION
FROM STUDENT z,ENROLLMENT b,SECTION w,COURSE m
WHERE z.STUDENT_ID = b.STUDENT_ID AND b.SECTION_ID = w.SECTION_ID AND w.COURSE_NO = m.COURSE_NO
AND m.DESCRIPTION = 'Systems Analysis' AND m.DESCRIPTION = 'Project Management')
ORDER BY FIRST_NAME, LAST_NAME, PHONE;
但是當我選擇這兩個「系統分析」和「項目管理」它給了我沒有行
SELECT FIRST_NAME, LAST_NAME, PHONE
FROM STUDENT d,ENROLLMENT f,SECTION g,COURSE h
WHERE d.STUDENT_ID = f.STUDENT_ID AND f.SECTION_ID = g.SECTION_ID AND g.COURSE_NO = h.COURSE_NO
AND h.DESCRIPTION = 'Systems Analysis' AND h.DESCRIPTION = 'Project Management'
AND DESCRIPTION NOT IN
(SELECT m.DESCRIPTION
FROM STUDENT z,ENROLLMENT b,SECTION w,COURSE m
WHERE z.STUDENT_ID = b.STUDENT_ID AND b.SECTION_ID = w.SECTION_ID AND w.COURSE_NO = m.COURSE_NO
AND m.DESCRIPTION = 'Systems Analysis' AND m.DESCRIPTION = 'Project Management')
ORDER BY FIRST_NAME, LAST_NAME, PHONE;
如何提供包含誰採取兩個系統的分析與學生名單項目管理課程不給我沒有行?
它確實工作!謝謝...不知道如果我明白答案 – Ris
看看這個:http://www.techonthenet.com/sql/intersect.php – Chandu
謝謝,這是想想 – Ris