用的是SQL SERVER 2012
有一张学生选课表SC,Sno是学号,Cno是课程号,Grade是成绩
现在要查询没有选修1号课程和2号课程的学生学号,
子查询的方法已经写出来了
请问可以转换成连接查询来做吗?
我尝试写了一下,通过Student与SC左连接,查询Cno为null或不为1和2的学号,
但是发现那些选了1和2号但是也选了其他的学生也查询出来了……
是不是不能转换成连接查询?
select *
from Student a
left join SC b on a.Sno=b.Sno
where b.Cno in('1','2')) and b.Sno is null
select a.Sno
from Student a
left join SC b on a.Sno=b.Sno
where b.Cno in('1','2') and b.Sno is null
这个不可能用连接吧,无论怎样都需要字查询的参与,进行筛选
select distinct sname,sdept from student left join sc on student.sno=sc.sno where student.sno not in (select sc.sno from sc where cno=1 or cno=2)