zoukankan      html  css  js  c++  java
  • mysql练习题-查询同时参加计算机和英语考试的学生的信息-遁地龙卷风

    (-1)写在前面

    文章参考http://blog.sina.com.cn/willcaty

    针对其中的一道练习题想出两种其他的答案,希望网友给出更多回答。

    (0) 基础数据

    student

    +-----+--------+------+-------+------------+--------------+

    | id  | name   | sex  | birth | department | address      |

    +-----+--------+------+-------+------------+--------------+

    | 901 | 张老大 | 男   |  1985 | 计算机系   | 北京市海淀区 |

    | 904 | 李四   | 男   |  1990 | 英语系     | 辽宁省阜新市 |

    | 905 | 王五   | 女   |  1991 | 英语系     | 福建省厦门市 |

    | 906 | 王六   | 男   |  1988 | 计算机系   | 湖南省衡阳市 |

    +-----+--------+------+-------+------------+--------------+

    score

    +----+--------+-----------+-------+

    | Id | Stu_id | C_Name    | Grade |

    +----+--------+-----------+-------+

    | 23 |    901 | 计算机    |    98 |

    | 24 |    901 | 英语      |    80 |

    | 25 |    902 | 计算机    |    65 |

    | 26 |    902 | 中文      |    88 |

    | 27 |    903 | 中文      |    95 |

    | 28 |    904 | 计算机    |    70 |

    | 29 |    904 | 英语      |    92 |

    | 30 |    905 | 英语      |    94 |

    | 31 |    906 | 计算机    |    90 |

    | 32 |    906 | 英语      |    85 |

    +----+--------+-----------+-------+

    (1)查询同时参加计算机和英语考试的学生的信息

    方式一:

    SELECT a.* FROM student a ,score b ,score c

        WHERE a.id=b.stu_id

        AND b.c_name='计算机'

        AND a.id=c.stu_id

    AND c.c_name='英语';

    方式二:

    SELECT *  FROM student

         WHERE id =ANY

         ( SELECT stu_id FROM score

         WHERE stu_id IN (

                  SELECT stu_id FROM

                  score WHERE c_name=  '计算机')

         AND c_name= '英语' );

    方式三:

    select * from student where id in(

    select s.stu_id from (select stu_id from score where c_name = '计算机') s

     (select stu_id from score where c_name='英语') as t where s.stu_id=t.stu_id)

    方式四:

     select * from student where id in (

     select stu_id from score where c_name ='计算机' and stu_id in(

     select stu_id from score where c_name ='计算机'));

     (2) 正确答案

    +-----+--------+------+-------+------------+--------------+

    | id  | name   | sex  | birth | department | address      |

    +-----+--------+------+-------+------------+--------------+

    | 901 | 张老大 | 男   |  1985 | 计算机系   | 北京市海淀区 |

    | 904 | 李四   | 男   |  1990 | 英语系     | 辽宁省阜新市 |

    | 906 | 王六   | 男   |  1988 | 计算机系   | 湖南省衡阳市 |

    +-----+--------+------+-------+------------+--------------+

  • 相关阅读:
    maven/gradle 打包后自动上传到nexus仓库
    idea中怎么忽略(ignore)掉 .idea等文件
    MySQL优化一例
    微信调用照相拍照等 js 接口的权限配置 和 照片上传和下载实现
    {"errcode":40097,"errmsg":"invalid args hint: [vjNe7xxxxxx8vr19]"}——记录一次微信错误处理
    jsmooth compilation failed error null
    java.lang.UnsatisfiedLinkError: %1 不是有效的 Win32 应用程序。
    IE8 ajax缓存问题
    com.sun.xml.internal.ws.server.ServerRtException: Server Runtime Error: java.net.BindException: Cannot assign requested address: bind
    chrome 浏览器的预提取资源机制导致的一个请求发送两次的问题以及ClientAbortException异常
  • 原文地址:https://www.cnblogs.com/resolvent/p/6131027.html
Copyright © 2011-2022 走看看