学生表 S(sid,name,sex,age)

课程表 C(cid,name)

学生选课关联表 SC(sid,cid,score)

 

查询选修全部课程的学生姓名:

select S.name from S where not exists(

   select * from C where not exists(

      select * from SC  where sid=S.sid and cid=C.cid 

     )

解释:

  最里层的子查询用于查找某个学生选修的所有课程;

  中间层的子查询(结合not exists)用于查找该学生没有选修的课程;

  最外层的查询(结合not exists)用于查找不存在“有几门课程没有选修”情况的学生,即选修了全部课程


原文链接:http://hi.baidu.com/liutingrex/blog/item/695a127bfeaddff20bd18718.html

相关文章:

  • 2022-12-23
猜你喜欢
  • 2021-08-10
  • 2022-01-07
  • 2021-07-21
  • 2021-11-18
  • 2021-08-18
  • 2021-11-18
相关资源
相似解决方案