黑马程序员技术交流社区

标题: 下面这个问题的SQL查询语句怎么写? [打印本页]

作者: 黄雄斌    时间: 2012-4-9 13:45
标题: 下面这个问题的SQL查询语句怎么写?
数据库中有如下一个表(SC),该表的字段为:序号(No )学生号(Sno) 学生姓名(Sname) 选修课程(Sdept) 成绩(Grade)
其中序号为主键且一个学生可选修多门课程
下面要查询:
          至少选修了学生200215122选修的全部课程的学生号码?
怎么在SQL语句表现出”至少“呢?
作者: 职业规划-蔡红微老师    时间: 2012-4-9 17:36
select Sno,Sname from Student,SC where Student.Sno=SC.Sno and Cno in (select Cno from SC where Sno='200215122');  
作者: 刘冬晓    时间: 2012-4-9 18:35
select Sno,COUNT(Sdept) from SC having COUNT(Sdept)>(select COUNT(Sdept) from SC where Sno=200215122) 你试试吧。
作者: 鲍晨    时间: 2012-4-9 20:37
用逻辑蕴含来表达,假设查询学号为x的学生,对所有的课程y,只要200215122选修了y,则x也选修课了y
select distinct sno from sc scx where not exists
(
select * from sc scy
where scy.sno='200215122' and not exists
  (
   select * from sc scz where
  scz.sno=scx.sno and scz.cno=scy.cno
  )
)
作者: pray    时间: 2014-4-26 08:06
我也来顶一下..




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2