SQL 的一个查询问题

kenko 2003-10-20 09:25:41
A
JNO SNO PNO
----------------
J1 S1 P1
J1 S2 P1
J1 S3 P2
J1 S2 P3
J2 S1 P2
J2 S2 P1
J3 S2 J1
J3 S3 J3
==================

上有 A 表,意思是:教授(JNO)指导学生(SNO)的课程(PNO)。

Q:哪些教授至少指导了学生S1所选的全部课程?

PS:学生S1所选的全部课程是P1和P2,因此,教授必须至少能够讲授课程P1和P2。
即教授J1和J2满足要求。

请写出语句,谢谢!




...全文
41 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
kenko 2003-10-20
  • 打赏
  • 举报
回复
wzh1215(四脚蛇) ,但最终结果好似有点问题?
kenko 2003-10-20
  • 打赏
  • 举报
回复
wzh1215(四脚蛇) ,你的结果是正确的 !!谢谢
kenko 2003-10-20
  • 打赏
  • 举报
回复
因为这是节选,整个程序还有其他的内容,所以不能select distinct JNO from A where SNO='S1'就可以了事
wzh1215 2003-10-20
  • 打赏
  • 举报
回复
select jno from a where jno not in(select jno from a aa where aa.jno not in(select jno from a bb where bb.sno='s1'))
结果:

jno
----------
J1
J1
J1
J1
J2
J2
J2

(7 row(s) affected)
结果错误。
大力的也是这个的结果!
wzh1215 2003-10-20
  • 打赏
  • 举报
回复
select jno from a where jno not in(select jno from a aa where jno not in(select jno,pno from a bb where bb.sno=s1) as cc) as dd
wuli81234 2003-10-20
  • 打赏
  • 举报
回复
这个题只用找出s1的所有指导教授就够了吧~~~后面的条件完全是多余的啊~~~~
wuli81234 2003-10-20
  • 打赏
  • 举报
回复
select distinct JNO from A where SNO='S1'

你的PS是废话!有误导作用
pengdali 2003-10-20
  • 打赏
  • 举报
回复
select jno from a aa where not exists (select * from a bb where b.sno='s1' and not exists (select * from a where pno=bb.pno and jno=aa.jno))

34,576

社区成员

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

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