我有以下表格
subject(id,name,sem,branch) //Detail of subject in sem and branch
teacher(id,name,dept) //detail of teacher
student_teacher_mapping(sid,tid) //primary key of student and teacher
section(id,sec) //detail of sections
subject_section_mapping(sid,secid) //primary key of subject and section
我想获取分支“计算机科学”的主题名称和教师名称,sem = 3和section ='d'。
答案 0 :(得分:0)
@Manish你看到你的表SUBJECT链接到SECTION,这将给我们一个SECTION,并且表SECTION没有链接到任何其他表,所以这里似乎有一个死胡同,数据库设计似乎是错误的。
答案 1 :(得分:0)
最后,我在没有你帮助的情况下完成了这项工作:/
我换了一张桌子 我的桌子是
subject(id,name,sem,branch) //Detail of subject in sem and branch
teacher(id,name,dept) //detail of teacher
section(id,sec) //detail of sections
sub_teacher_sec (subject_id,teacher_id,section_id) //primary key of subject,teacher and section
这是我的查询,以获取主题名称,教师名称和空间分支学期和部分值的部分
select sub.name,t.name,se.sec from subjects as sub
join
sub_teacher_sec as sts
on
sts.subject_id=sub.id
join
teachers as t
on
sts.teacher_id=t.id
join
section as se
on
sts.section_id=se.id
and sub.semester=3 and sub.branch='CSE';
表中或查询中是否有任何更正请建议。