zoukankan      html  css  js  c++  java
  • 15-成绩2

    
    
    create table score(
    name string,
    chinese string,
    math string
    )
    row format delimited fields terminated by ','
    lines terminated by '
    '
    stored as textfile;
    load data local inpath '/score.txt' into table score;
    
    create table class(
    name string,
    cname string
    )
    row format delimited fields terminated by ','
    lines terminated by '
    '
    stored as textfile;
    load data local inpath '/class.txt' into table class;
    
    数学最高分的学生所在班级的平均成绩?
    1.求出数学的最高分
    2.根据最高分求出这个学生
    3.根据学生查询班级
    4.根据班级查询学生
    5.根据学生查询出成绩
    6.根据成绩查询平均值
    select avg(s.math)
    from
    class c,score s,
    (select c.cname
    from class c,score s,
    (select max(math) max from score)t
    where s.math = t.max and s.name = c.name)t1
    where t1.cname=c.cname and c.name = s.name
    
    
    1.数学和语文平均成绩均大于60分的班级和平均成绩
    
    数学成绩大于60分的班级
    select t1.math,t2.chinese,t1.cname
    from
    (select avg(math) math,cname
    from score s join class c on s.name = c.name
    group by cname having avg(math)>60) t1
    join
    (select avg(chinese) chinese,cname
    from score s join class c on s.name = c.name
    group by cname having avg(chinese)>60)t2
    on 
    t1.cname = t2.cname
    语文大于60分的班级
    
    select c.cname,avg(s.math),avg(s.chinese)
    from
    class c,score1 s
    where c.name = s.name
    group by c.cname
    having avg(s.math)>60 and avg(s.chinese)>60
    
    
    2.
    查询语文成绩大于60
    数学成绩大于60
    
    select t1.cname,t1.math,t2.chinese from
    (select avg(s.math) as math,c.cname
    from class c,score1 s
    where c.name = s.name
    group by c.cname
    having avg(s.math)>60)t1
    join
    (select avg(s.chinese) as chinese,c.cname
    from class c,score1 s
    where c.name = s.name
    group by c.cname
    having avg(s.chinese)>60)t2
    where t1.cname = t2.cname;

    数据

    banzhang,89,98
    tuanzhishu,99,89
    xiaoming,55,66
    xiaohong,88,66
    xiaolong,55,66
    xiaoliang,88,99
    xiaoming,c1
    xiaohei,c2
    banzhang,c3
    tuanzhishu,c2
    xiaohong,c1
    xiaolong,c2
    xiaoliang,c3
    

      

  • 相关阅读:
    SQLdiag-配置文件-ProfilerCollector
    SQLdiag-配置文件-PerfmonCollector
    SQLdiag-初识
    Trace-跟踪高消耗的语句需添加哪些事件
    RML Utilities for SQL Server
    【译】第十五篇 Integration Services:SSIS参数
    修改数据文件和日志文件路径
    Trace-导出已有的服务器端跟踪
    iphoneX的适配问题
    添加阿里巴巴图标,让你页面小图标都是CSS3写成
  • 原文地址:https://www.cnblogs.com/JBLi/p/10848947.html
Copyright © 2011-2022 走看看