题目:输入语句,利用NOT EXISTS谓词,查询没有选修“软件工程”的学生的学号和姓名
这个问题我想了好久,刚开始我是这样写的:
select student.sno,sname from student inner join sc
on student.sno=sc.sno
where not exists(select * from course where course.cno=sc.cno and cname='软件工程')
go
结果:
我一直搞不明白那里出错了,然后直接简单暴力一点,用select嵌套语句:
select student.sno,sname from student
where not exists(select * from course
where exists(select * from sc where student.sno=sc.sno and sc.cno=course.cno and cname='软件工程'))
go
结果就出来了:
如果有知道前面的语句那里错的请指教!
本文探讨了一种使用SQL NOT EXISTS谓词查询未选修特定课程的学生信息的方法。通过对比两种不同写法的结果,解释了为何第一种写法无法得到正确答案,并提供了一个可行的解决方案。


被折叠的 条评论
为什么被折叠?



