SQL Server 问题提问查询选修了全部课程的学生姓名s
sqlserver吧
全部回复
仅看楼主
level 2
威仔糕🌠 楼主
SQL Server 问题提问
查询选修了全部课程的学生姓名
select sname
from student
where not exists
(select *
from course
where not exists
(select *
from sc
where sno =student.sno
and cno=course.cno)
1-为何要用not exists?
2-我把两个not去掉为何不行[阴险]
3-还有sno =student.sno是什么意思?sno是student还是sc表的
4-同问cno=course.cno
5-感谢大佬求大佬解答[小乖]
2018年11月18日 08点11分 1
level 9
最里层是某学生没选的课,中间那层是某学生没有没选的课,最外层把这些学生选出来
2018年11月22日 18点11分 2
level 9
感觉不用三层这么复杂,distinct查多少门课,直接group by 姓名,count函数判断,
2018年11月22日 18点11分 3
level 4
select Sname
from student
where exists
(select *
from course
where exists
(select *
from sc
where sno =student.sno and cno=course.cno)
--前一个sno是SC里的,前一个cno是sc里的,SC.可有可无,但是后面的必不可少
)
--意思是(存在)没有一门课程是他不选的,双重否定,第二个not exists(存在)没有一门课程,第一个not exists(存在)一门都没有选,如果都不加not,意思是他选了一门课或多门课(只要选课的学生都会select出)
2018年11月28日 03点11分 4
1