0

我正在尝试提供一个列表,其中包含参加过系统分析和项目管理课程的学生。

当我单独选择“系统分析”或“项目管理”时,它会给我结果,但不是我需要的。我需要参加过这两门课程的学生。

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;

如何提供一个包含已参加系统分析和项目管理课程的学生的列表而不给我任何行?

4

2 回答 2

1

试试这个:

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' 
INTERSECT
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 = 'Project Management' 
于 2013-10-17T00:05:25.867 回答
1

或者

SELECT stud.FIRST_NAME, stud.LAST_NAME, stud.PHONE
FROM STUDENT stud,
inner join ENROLLMENT enr On stud.Student_ID = enr.student_ID
inner join SECTION sec On sec.Section_ID = enr.Section_ID
inner join COURSE syst On syst.course_no = sec.Course_No
inner join COURSE proj On proj.Course_no = sec.Course_No
Where syst.DESCRIPTION = 'Systems Analysis' 
AND proj.DESCRIPTION = 'Project Management' 
ORDER BY stud.FIRST_NAME, stud.LAST_NAME, stud.PHONE

如果我正确地翻阅了这些别名,您就可以找到有意义的别名。哦,并使用正确的连接语法。诀窍是参加两次课程,一次用于系统分析,一次用于项目管理。

PS如果那里有sql课程,我建议你参加。

于 2013-10-17T00:17:03.207 回答