我有以下数据。我有三个表:学生表、课程表和StudentCourse表
学生( Sid,Sname,Sbranch,Sage) -包含学生ID,姓名,他们各自的分支和年龄。此外,大学只有CSE、EEE和IT三个分支机构。
StudentCourse( Sid,Cid) -这包含学生ID和课程ID --这传达了哪个学生注册了哪门课程。
Course( Cid,Cname,CCredits) -包含课程ID、课程名称和课程所带学分的数量。该学期共有四门课程,分别是操作系统、数据库管理系统、CNW和PHY。
如何编写一个查询来获得所有EEE学生注册的课程的cid,cname。
发布于 2017-03-22 04:57:34
不清楚您的表的结构,但根据您的描述,您可以尝试如下操作(完全按照数据库中的表名更改表的名称):
select distinct ct.c_name
from student_table st,
student_course sc,
course_table ct
where st.st_branch = 'EEE'
and st.st_id = sc.st_id
and ct.c_id = c_id;另外,如果你把你尝试过的东西贴出来也是很好的。
发布于 2017-03-22 07:04:16
像这样的东西应该是有效的:
select c_id, c_name
from course c
where not exists (
select st_id
from student
where st_branch = 'EEE'
and (st_id, c.c_id) not in (
select st_id, c_id
from student_course
)
)
;发布于 2017-03-22 13:41:15
此解决方案可能会得到您所期望的结果
select distinct
c.cid,
cname,
from course c
join StudentCourse sc on c.cid=sc.cid
join student s on s.sid=sc.sid
where sbranch='EEE';https://stackoverflow.com/questions/42937262
复制相似问题