学生表 :Student(S(学号),Sname(姓名),Sage(年龄),Ssex(性别))
课程表 :Course(C(课程编号),Cname(课程名称),T(教师编号))
成绩表 :SC(S(学号),C(课程编号),score(分数))
教师表 :Teacher(T(教师编号),Tname(姓名))
select st.*
from Student st
where not exists (select 1
from SC, Course c, Teacher t
where st.s = sc.s
and sc.c = c.c
and t.t = c.T
and t.T = '01');
where子查询执行效率是否低于表连接,为什么?
select 1
from SC, Course c, Teacher t
where st.s = sc.s
and sc.c = c.c
and t.t = c.T
and t.T = '01' 这部分是查询张三授课的同学都有谁,并且用st.s = sc.s 跟外面嵌套的查询做关联,最外面的就是从学生中查询不是子查询中的(张三授课的同学),
where子查询执行效率是否低于表连接 ,这个不一定,这个是需要具体问题具体分析,有时候用子查询可以限制一部分条件,会比直接表连接快,特别是数据量大的时候