请大家帮忙解释一下这条sql语句

tomorrow0567 2003-09-11 04:51:12
数据库中有三个关系(基本本)
s(s#,sname,age,sex)
sc(s#,c#,grade)
c(c,cname,teacher)
检索学习全部课程的学生姓名
实现的语句是:
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#))
看不懂。请高手帮忙解释一下。谢谢
...全文
49 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
FeelingL 2003-09-11
  • 打赏
  • 举报
回复
--查询s3学生没有学习的课程
(select c# from c where not exists(select * from sc where sc.s#='s3' and sc.c#=c.c#))

--某学生没有学习的课程
(select * from c where not exists(select * from sc where sc.s#=s.s# and sc.c#=c.c#))

--不存在没有学习的课程的学生(即学习了所有课程的学生)
select s#,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#))

--建议学习关系代数的除法
--类似问题:查询学习了某学生所学的课程的学生
pubble 2003-09-11
  • 打赏
  • 举报
回复
写的真烂
FeelingL 2003-09-11
  • 打赏
  • 举报
回复
直接意思:不存在这样的课程,学生没有学!
FeelingL 2003-09-11
  • 打赏
  • 举报
回复
此SQL语句的功能:查询学习了所有课程的学生姓名!
有点搞,不过你从后面往前面推导,应该能明白

34,575

社区成员

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

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