我是甲骨文的新手。如何找到符合先决条件的学生
SELECT
c.course_no,
c.description,
c.prerequisite,
level AS level_course,
stu.student_id
FROM
course c
INNER JOIN section s ON c.course_no = s.course_no
INNER JOIN enrollment e ON s.section_id = e.section_id
INNER JOIN student stu ON e.student_id = stu.student_id
CONNECT BY
PRIOR c.course_no = c.prerequisite
[1]:https://i.stack.imgur.com/SNG0G.png 课程表
[1]:https://i.stack.imgur.com/Asy8F.png ENROLLMENT TABLE https://i.stack.imgur.com/1axEi.png SECTION TABLE
答案 0 :(得分:0)
您可能需要在START WITH
之前添加CONNECT BY
。
这里以course_no 20为例。
您可以删除AND c.course_no = 20
以查看所有课程。
注意:还调整了列以使其更清晰
SELECT
level AS level_course,
c.course_no,
e.section_id,
c.prerequisite,
c.description,
stu.student_id
FROM
course c
INNER JOIN section s ON c.course_no = s.course_no
INNER JOIN enrollment e ON s.section_id = e.section_id
INNER JOIN student stu ON e.student_id = stu.student_id
START WITH c.prerequisite IS NULL AND c.course_no = 20
CONNECT BY
PRIOR c.course_no = c.prerequisite