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分)---------


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

  • 相关阅读:
    jQuery..1..基本使用..选择
    ORZ各路神犇
    马上搞定Android平台的Wi-Fi Direct开发
    Linux环境下搭建Android开发环境
    笑谈接口回调
    AIDL通信原理
    某个Java面试题
    直接下载SpringBoot项目本地的Excel文件
    用JSP做后台管理系统
    Singleton
  • 原文地址:https://www.cnblogs.com/jiao-/p/7301018.html
Copyright © 2011-2022 走看看