初来乍到,请多多指教。

Amanda591 2003-05-30 08:55:34
谁能帮忙解释以下SQL语句中的exist的用法。尤其是他在双重否定上的用法。不胜感激!
...全文
20 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
happydreamer 2003-05-30
  • 打赏
  • 举报
回复
三个表:
1、学生表:STUDENT
学号 名字
SID SNAME
1 WAN
2 NAM
3 DNA
2、课程表: COURCE
课号 名字
CID CNAME
1 EN
2 CN
3 US
3、成绩 SC
学号 课程号 得分
SID CID SCORE
1 1 90
1 2 67
1 3 30
2 3 46
3 1 89




--求有参加过课程的人
select sname from student where exists(
select * from cource where exists(
select * from sc where sc.sid=student.Sid and
sc.cid=cource.cid))

--求有 没有参加课程的人
select sname from student where exists(
select * from cource where not exists(
select * from sc where sc.sid=student.Sid and
sc.cid=cource.cid))

--求有参加所有课程的人
select sname from #student where not exists(
select * from cource where not exists(
select * from sc where sc.sid=student.Sid and
sc.cid=cource.cid))

34,576

社区成员

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

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