我想要获得ID为444111110的学生可以注册的课程。 可以注册的课程是没有先决条件或课程的课程 他已经取得的先决条件并在其中取得了成绩。
学生退学的课程也必须展示,所以他可以再次注册。它将在等级栏中给出“W” 不得展示学生所选课程和课程。 如果他已经参加了这门课程,那么它将在成绩栏中获得“U”。
#COURSE_ID PREREQUISITE_COURSE_ID
CS111 NULL
CS211 CS111
CS244 CS311
CS244 CS211
CS244 CS111
CS311 CS211
CS311 CS111
# STUDENT_ID COURSE_ID DATEREGISTERED EnrollToken GREADE
444111110 CS111 2005-03-10 5 A
444111110 CS211 2005-03-10 7 A+
444111111 CS111 2005-03-10 6 W
# COURSE_ID COURSE_NAME TERM CREDITS_HOUR SEATS_LEFT
CS111 Intro. to CS 1 3 50
CS211 Intro. to PS 2 3 50
CS244 Adcanced Application 4 3 50
CS311 Introduction to OOB 3 3 50
我试过这个查询
SELECT DISTINCT C.COURSE_ID, C.COURSE_NAME, C.SEATS_LEFT
FROM ENROLLMENT E, PREREQUISITE P, COURSES C
WHERE C.COURSE_ID NOT IN (SELECT COURSE_ID FROM ENROLLMENT WHERE STUDENT_ID = '444111110' AND GREADE !='U')
AND P.PREREQUISITE_COURSE_ID IN
(SELECT COURSE_ID FROM ENROLLMENT WHERE STUDENT_ID = '444111110' AND GREADE !='W');
但它返回CS244和CS311给id为444111110的学生,而它应该只返回CS311。
对于没有注册任何课程或退出CS111的第一门课程的学生,也不会返回任何内容。
是否有可能的方法来检查学生是否将所有必修课程都纳入其中? 并且有一种方法可以为没有注册任何课程的学生修复该查询,以证明他们可以注册CS111,其先决条件是NULL吗?
提前致谢。
答案 0 :(得分:0)
,试试这个
select course_ID, COURSE_NAME, SEATS_LEFT from Courses
where course_ID in (select course_ID from Enrollment where grade ='W')
or course id in (select course_id from Prerequisites where prerequisite_course_id in (select course_ID from Enrollment where grade != 'W')
答案 1 :(得分:0)
SELECT COURSE_ID,COURSE_NAME,SEATS_LEFT FROM Courses WHERE Course_ID NOT IN (
SELECT Course_ID FROM prerequisite WHERE PREREQUISITE_COURSE_ID IN
(SELECT Course_ID FROM Courses WHERE Course_ID NOT IN
(SELECT Course_ID FROM Enrollment WHERE Student_ID = '444111110' AND GREADE NOT IN ('U', 'F', 'W') ) ) ) AND Course_ID NOT IN
(SELECT Course_ID FROM Enrollment WHERE Student_ID = '444111110' AND (GREADE = 'U' OR GREADE NOT IN ('F', 'W') ) );
我要感谢我的导师为我解决这个问题。