zoukankan      html  css  js  c++  java
  • 查询选修了全部课程的学生姓名_如何解?-MS-SQLServer/应用实例

    查询选修了全部课程的学生姓名
    :student 是学生表 course 是选课表 sc 是课程表
    select sname
    from student
    where not exists
    (select *
    from course
    where not exists  
    (select *
    from sc
    where sno =student.sno
    and cno=course.cno)
    如何解释呢?我只是约约的明白,但就是给别人解释不明白。希望高手给解释一下。

    ------回答---------
    ------其他回答(10分)---------


    select *
    from course
    where not exists   
    (select *
    from sc
    where sno =student.sno
    and cno=course.cno)
    这一段计算得出 某学生存在没有选的课程
    如果外层再加上 一个不存在 没有选的课程。那就是全选了

    ------其他回答(10分)---------
    SQL code
    -- 从里往外分析 select * from student -- (3) where not exists ( select * from course -- (2) where not exists ( select * from sc where sno=student.sno -- (1) and cno=course.cno ) ); -- (1) 查找某一个学生所选的所有课程 select * from sc where sno=student.sno -- (2) 查找这个学生没有选修的课程 select * from course c where not exists ( select * from sc where sno=student.sno and cno=course.cno) -- (3) 排除这个没有选修所有课程的学生
    ------其他回答(4分)---------


    负负得正,不存在任何一科没有选修的,也就是每科都选修了

  • 相关阅读:
    分布式任务调度平台XXL-JOB搭建教程
    微服务跨域问题
    getway网关跨域问题记录
    MySQL-数据库简介及mysql5.7安装
    MongoDB-备份和恢复
    MongoDB-复制集rs及sharding cluster
    MongoDB
    Redis-API支持
    Redis-主从复制,哨兵机制及redis cluster
    Redis-简介及基本数据类型
  • 原文地址:https://www.cnblogs.com/jiao-/p/7301018.html
Copyright © 2011-2022 走看看