zoukankan      html  css  js  c++  java
  • 操作 mysql练习14-16题

    14 查询和“02”号的同学学习的课程完全相同的其他同学学号和姓名(同12题)

    select s.s_id, s.s_name from student s join

    (select s_id, count(c_id) num from score where c_id in

    (select c_id from score where s_id='02') and s_id<>'02'

    group by s_id

    having num=(select count(c_id) from Score where s_id='02')

    ) r on s.s_id=r.s_id

     

    参考答案

    select a.s_id,a.s_name

    from Student a join Score b on a.s_id=b.s_id

    where c_id in (select c_id from Score where s_id='02')

    and a.s_id <> '02'

    group by a.s_id

    having count(c_id)=(select count(c_id) from Score where s_id='02');

    15 删除学习“张三”老师课的SC表记录(删除张三老师在course表中的记录,SC应该是student course吧)

    delete from score

    where c_id in

    (select c_id from course c join teacher t on c.t_id=t.t_id where t_name='张三');

     

    16 查询各科成绩最高和最低的分:以如下的形式显示:课程ID,最高分,最低分

    select c_id '课程ID',max(s_score) '最高分', min(s_score) '最低分' from score group by c_id;

     

  • 相关阅读:
    读书计划(2020年秋)
    Hbase 常用Shell命令
    假期第三周总结
    语义分析
    虚拟机安装
    掌握需求过程读后感
    第八周总结
    SLR1分析
    第七周总结
    需求工程阅读笔记(三)
  • 原文地址:https://www.cnblogs.com/leejunwei/p/mysql_exercises03.html
Copyright © 2011-2022 走看看