查询选修了全部课程的学生姓名_如何解?-MS-SQLServer/应用实例

查询选修了全部课程的学生姓名
:student 是学生表 course 是选课表 sc 是课程表
select sname
from student
where not exists
(select *
from course
where not exists  
(select *
from sc
where sno =student.sno
and cno=course.cno)
如何解释呢?我只是约约的明白,但就是给别人解释不明白。希望高手给解释一下。

------回答---------

 

------其他回答(10分)---------


select *
from course
where not exists   
(select *
from sc
where sno =student.sno
and cno=course.cno)
这一段计算得出 某学生存在没有选的课程
如果外层再加上 一个不存在 没有选的课程。那就是全选了

------其他回答(10分)---------

 

SQL code
-- 从里往外分析 select * from student -- (3) where not exists ( select * from course -- (2) where not exists ( select * from sc where sno=student.sno -- (1) and cno=course.cno ) ); -- (1) 查找某一个学生所选的所有课程 select * from sc where sno=student.sno -- (2) 查找这个学生没有选修的课程 select * from course c where not exists ( select * from sc where sno=student.sno and cno=course.cno) -- (3) 排除这个没有选修所有课程的学生
------其他回答(4分)---------


负负得正,不存在任何一科没有选修的,也就是每科都选修了

转载于:https://www.cnblogs.com/jiao-/p/7301018.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值