zoukankan      html  css  js  c++  java
  • mysql——单表查询——聚合函数——示例

    create table score ( xh int(50),
                         km varchar(50),
                         cj int(50)
                       );
    
    select * from score;
    
    insert into score values(1,'shuxue',80);
    insert into score values(1,'yuwen',70);
    insert into score values(1,'yingyu',40);
    
    insert into score values(2,'shuxue',40);
    insert into score values(2,'yuwen',60);
    insert into score values(2,'yingyu',50);
    
    insert into score values(3,'shuxue',60);
    insert into score values(3,'yuwen',20);
    insert into score values(3,'yingyu',90);
    
    insert into score values(4,'shuxue',50);
    insert into score values(4,'yuwen',60);
    insert into score values(4,'yingyu',70);
    
    select xh,sum(cj) from score where xh = 1;   查询此同学的总成绩;
    select xh,sum(cj) from score where xh = 4;
    
    select xh,sum(cj) from score group by xh;     查询每一个同学的各科总和成绩;
    
    select km,max(cj) from score group by km;      查询各个科目的最高成绩;
    
    select km,avg(cj) from score group by km;   查询每一科目的平均成绩;
    
    select km,max(cj) from score group by km;    查询每一科目的最高成绩;
    
    select km,min(cj) from score group by km;    查询每一科目的最低成绩;
  • 相关阅读:
    SVG平移和缩放(鼠标滚轮)的实现
    CSS之容器水平垂直居中
    CSS之flex布局
    CSS之鼠标悬停——内容变深/变浅
    CSS之clip-path绘制多边形
    axios
    .Net 反射
    Redis
    .Net Core GRPC报错
    Python 京东云无线宝消息推送
  • 原文地址:https://www.cnblogs.com/xiaobaibailongma/p/12092947.html
Copyright © 2011-2022 走看看