大致思路:分步+内嵌查询
Step1:查询课程为''001''和"002"所有情况:
select * from sc where cid = 1
select * from sc where cid = 2
Step2:根据步骤一,利用内嵌查询,查询同时修了两门课的学生id:
select t1.sid from (
(select s1.sid from sc s1 where s1.cid = 1) t1,
(select s2.sid from sc s2 where s2.cid = 2) t2
)where t1.sid = t2.sid
Step3:学生表和步骤二的表联立,得到最终的结果:
select st.sid, st.sname from(
select t1.sid from
(select s1.sid from sc s1 where s1.cid = 1) t1,
(select s2.sid from sc s2 where s2.cid = 2) t2
where t1.sid = t2.sid
)stu, student st
where stu.sid = st.sid