检索学习全部课程的学生姓名,请高手帮助解释一下,100分

wujiabao 2005-09-01 11:13:11
如题:

有三个表
学生表 s(s#,sname,sex,age),课程表c(c#,cname,teacher),学习表sc(s#,c#,grade).
执行语句:
select sname from s where not exists((select * from c where not exists(select * from
sc where sc.s#=s.s# and sc.c#=c.c#)))
执行结果正确,但不知道为什么这么做。请高手指教,解释越详细得分越高,不够再加
...全文
1307 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
filebat 2005-09-01
  • 打赏
  • 举报
回复
你好好理解一下这一句话:"不存在一门课,该学生没有选"

有些东西,只是意会不能言传.

如果说的话,只会越说越乱,越说越麻烦.

至少这个问题,我是这样想的.
filebat 2005-09-01
  • 打赏
  • 举报
回复
楼主,你那个是经典解法

双重否定就是肯定.
iwl 2005-09-01
  • 打赏
  • 举报
回复
其实就是相关子查询,最里边的子查询是为了找出学生选择的所有课程,中间的子查询是为了找出学生没选的课程。
wujiabao 2005-09-01
  • 打赏
  • 举报
回复
有没有更详细的解释呀
samfeng_2003 2005-09-01
  • 打赏
  • 举报
回复
:( 我还以为在做题哈!最里面的最后面的语句是为了选择所有学生选择的课程,加上not exists 表示在c表中查找到学生们没有选中的课程,最外面的表示在这个集合中找到与S表中对应的,选择了所有课程(也就是没有没选中的课程的)的同学的名字
danisluo 2005-09-01
  • 打赏
  • 举报
回复
就是一层一层排除没选课程的人
samfeng_2003 2005-09-01
  • 打赏
  • 举报
回复
检索全部学生都选修的课程的课程号和课程名
select c#,cname from c where not exists (select * from s where not exists (select * from sc where sc.c#=c.c# and sc.s#=s.s#))
检索选修了所有课程的同学
select s#,sname from s where not exists (select * from c where not exists (select * from sc where sc.c#=c.c# and sc.s#=s.s#))
hefang116 2005-09-01
  • 打赏
  • 举报
回复
select * from s
where s# in
(select s# from sc group by s# having count(s#)=(select count(*) from c))
子陌红尘 2005-09-01
  • 打赏
  • 举报
回复
其实就是相关子查询,最里边的子查询是为了找出学生选择的所有课程,中间的子查询是为了找出学生没选的课程。
子陌红尘 2005-09-01
  • 打赏
  • 举报
回复
偶习惯这么写:

select
*
from
s
where
(select count(distinct c#) from c) = (select count(distinct c#) from sc where s#=s.s#)
lisiyong 2005-09-01
  • 打赏
  • 举报
回复
双重否定就肯定了
zhangzhexin 2005-09-01
  • 打赏
  • 举报
回复
select sname
from s
where s.s# in(
select sc.s#
from sc,c
where sc.c#=c.c#
group by sc.s#
having sc.s# = (select count(C#)
from C))
wgsasd311 2005-09-01
  • 打赏
  • 举报
回复
我们换一种思路可以容易理解,
查‘002’学生没有选修的课程 
select * from c where c# not in (select #c from sc where s#='002')
<==>
select * from c where not exists (select * from sc where s#='002' and c.c#=sc.c#)
上面两种是等价的,如你不能理解,那也就理解不了我下面要说的了。

查所有学生存在没有选修的课程的姓名
select sname from s where exists(
select * from c where c# not in (select #c from sc where sc.s#=s.s#)
)
<==>
select sname from s where exists(
select * from c where not exists (select * from sc where sc.s#=s.s# and c.c#=sc.c#)
)
查所有学生不存在没有选修的课程的姓名

select sname from s where not exists(
select * from c where c# not in (select #c from sc where sc.s#=s.s#)
)
<==>
select sname from s where not exists(
select * from c where not exists (select * from sc where sc.s#=s.s# and c.c#=sc.c#)
)
spland 2005-09-01
  • 打赏
  • 举报
回复
你好好理解一下这一句话:"不存在一门课,该学生没有选"
-------------------------------------------------
对就是这个意思,一个典型的双重否定的例子
wgsasd311 2005-09-01
  • 打赏
  • 举报
回复
select sname from s where not exists((select * from c where not exists(select * from
sc where sc.s#=s.s# and sc.c#=c.c#)))
-----------上面语句比较傲口,总体思路是,查找在课程表(c)不存在{ not exists(select * from c...)}任何一门课程此学生没有{not exists(select * from sc ... }学习过的所有学生姓名{select sname from s....}。
课程适合具有一定深度学习基础,希望发展为深度学习之计算机视觉方向的算法工程师和研发人员的同学们。基于深度学习的计算机视觉是目前人工智能最活跃的领域,应用非常广泛,如人脸识别和无人驾驶中的机器视觉等。该领域的发展日新月异,网络模型和算法层出不穷。如何快速入门并达到可以从事研发的高度对新手和中级水平的学生而言面临不少的挑战。精心准备的本课程希望帮助大家尽快掌握基于深度学习的计算机视觉的基本原理、核心算法和当前的领先技术,从而有望成为深度学习之计算机视觉方向的算法工程师和研发人员。本课程系统全面地讲述基于深度学习的计算机视觉技术的原理并进行项目实践。课程涵盖计算机视觉的七大任务,包括图像类、目标检测、图像割(语义割、实例割、全景割)、人脸识别、图像描述、图像检索、图像生成(利用生成对抗网络)。本课程注重原理和实践相结合,逐篇深入解读经典和前沿论文70余篇,图文并茂破译算法难点, 使用思维导图梳理技术要点。项目实践使用Keras框架(后端为Tensorflow),学员可快速上手。通过本课程学习,学员可把握基于深度学习的计算机视觉的技术发展脉络,掌握相关技术原理和算法,有助于开展该领域的研究与开发实战工作。另外,深度学习之计算机视觉方向的知识结构及学习建议参见本人CSDN博客。本课程提供课程资料的课件PPT(pdf格式)和项目实践代码,方便学员学习和复习。本课程为上下两部,其中上部包含课程的前五章(课程介绍、深度学习基础、图像类、目标检测、图像割),下部包含课程的后四章(人脸识别、图像描述、图像检索、图像生成)。

34,594

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧