【发布时间】:2018-08-17 04:38:09
【问题描述】:
下面有表格;
Course(cname, ccode, credit, dept) // course table.
Section(sno, ccode, semestr, year, prof); // course and lectures according to year and semester value.
Prerequisite(ccode, precode) // prerequisite for any course.
问题:
列出 2012 年开设的课程和必修课程 - 两者的代码和名称
我尝试通过加入来解决它。
select c.ccode, c.cname, p.precode from Course as c
inner join prerequisite as p on p.ccode=c.ccode;
查询返回下面的元组。
Course | Name | Pre. code
B201 | software engineering | B101
B202 | operating system | B101
H202 | civil law | H102
我怎样才能得到必修课程的名称和代码? 期望的结果必须低于;
Course | Name | Pre. code | Pre. name
B201 | software engineering | B101 | aaaaa
B202 | operating system | B101 | aaaaa
H202 | civil law | H102 | bbbb
【问题讨论】:
-
你的课程和先修课有什么关系?是多对一还是多对多。如果你能发布关系的图片就更好了
-
多对多,一门课程有不止一门必修课,一门课程是多门课程的必修课。我没有ER图。问题来自我的数据库考试。
-
你需要加入预编码课程的名字
标签: sql join subquery inner-join