简体   繁体   English

连接两个表检查一个表的值以显示第二个表的结果

[英]Joining two tables checking values of one table to display result of the second table

I have these two tables: COURSE and COURSE_SEQUENCE_REPORT我有这两个表:COURSE 和 COURSE_SEQUENCE_REPORT

课程

COURSE_SEQUENCE_REPORT

I am trying to display course number, course name, course prerequisite number and course prerequisite name.我正在尝试显示课程编号、课程名称、课程先决条件编号和课程先决条件名称。 The prerequisite ID is a is obtained as a relation to the course ID.先决条件 ID 是作为与课程 ID 的关系获得的。 If the presequisite ID is 11 then the prerequisite name is Mathematics from the course ID.如果先决条件 ID 为 11,则先决条件名称是课程 ID 中的数学。 I was able to come up with this:我能够想出这个:

SELECT C.COURSE_NUMBER AS "COURSE NUMBER", 
C.COURSE_NAME AS "COURSE NAME"
FROM COURSE C JOIN COURSE_SEQUENCE_REPORT CSR
ON CSR.COURSE_ID = C.COURSE_ID
ORDER BY C.COURSE_NUMBER;

...but I am left with the course prerequisite number and name. ...但我留下了课程先决条件编号和名称。 How do I go about it please?请问我该怎么做? I am confused.我很迷惑。

You want two joins:你想要两个连接:

SELECT C.COURSE_NUMBER AS COURSE_NUMBER, 
       C.COURSE_NAME AS COURSE_NAME,
       CP.COURSE_NUMBER AS PREREQUISITE_NUMBER, 
       CP.COURSE_NAME AS PREREQUISITE_NAME       
FROM COURSE_SEQUENCE_REPORT CSR JOIN
     COURSE C
     ON CSR.COURSE_ID = C.COURSE_ID JOIN
     COURSE CP
     ON CSR.PREREQUISITE_ID = CP.COURSE_ID
ORDER BY C.COURSE_NUMBER;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM