zoukankan      html  css  js  c++  java
  • 聚合函数

    聚合函数
        使用技巧,先不管聚合函数,先使用sql语句把要聚合的内容先查出来,然后再用聚合函数把要聚合的内容包起来
        1. count聚合函数,用来统计行数
        ~ 统计一个班共有多少学生
            select count(*) from exam;
          使用别名name_count 
            select count(*) name_count from exam;
        ~ 统计数学成绩大于70的学生有多少?
            select count(*) from exam where math>70;
        ~ 统计总分大于230的人数有多少?
            select count(*) from exam where math+english+chinese>230;
            
        2. sum聚合函数,求符合条件的某列的和值
        ~ 统计一个班级数学总成绩?
            select sum(math) from exam;
        ~ 统计一个班级语文,英语,数学各科的总成绩
            select sum(math),sum(english),sum(chinese) from exam;
        ~ 统计一个班级语文,英语,数学的成绩总和
            select sum(math+english+chinese) from exam;
        ~ 统计一个班语文成绩的平均分
            select sum(chinese)/count(*) from exam;
            
        3. avg聚合函数,求符合条件的列的平均值
        ~ 求一个班级数学平均分
            select math from exam;
        ~ 求一个班级总分平均分
            select avg(math+english+chinese) from exam;
        
        4. max/min聚合函数,求符合条件的列的最大值和最小值
        ~ 求班级最高分和最低分
            select max(math+english+chinese) from exam;
            select min(math+english+chinese) from exam;
  • 相关阅读:
    ByteBuffer用法总结
    内部类访问外部同名属性或者方法
    floodlight 学习(一)
    ubuntu 更改文件所有者
    python cmd 模块
    matlab 矩阵
    python操作MySQL数据库
    Win 7 下制作 mac 系统启动U盘
    Window 常用命令
    大数据扫盲
  • 原文地址:https://www.cnblogs.com/zhuhaofeng/p/15732184.html
Copyright © 2011-2022 走看看