题目六、
6、查询学过“001”并且也学过编号“002”课程的同学的学号、姓名;
select t1.sid as 学号,t3.sname as 姓名 from sc t1,sc t2 ,student t3 where t1.cid='001'and t2.cid='002' and t1.sid=t2.sid
and t1.sid=t3.sid;
1、首先查询出既学过“001”并且也学过编号“002”课程的同学的学号;
select t1.sid from sc t1,sc t2 where t1.cid='001'and t2.cid='002' and t1.sid=t2.sid ;
查询结果如下:
2、然后再和student 进行关联
select t1.sid as 学号,t3.sname as 姓名 from sc t1,sc t2 ,student t3 where t1.cid='001'and t2.cid='002' and t1.sid=t2.sid
and t1.sid=t3.sid;
最终查询结果如下: