• 22-9 聚合函数


    SQL 聚合函数(把多条数据变成一条,需要用到分组,然后统计):

    MAX(最大值)、MIN(最小值)、AVG(平均值)、SUM(和)、COUNT(数量:记录的条数)

    select * from TblStudent 
    
    --统计出所有人的年龄的总和
    select sum(tsage) as 年龄总和 from TblStudent
    
    --统计当前表中一共有多少条记录
    select count(*) from TblStudent
    
    --计算平均年龄
    select 平均年龄=(select sum(tsage) as 年龄总和from TblStudent)*1.0/(select count(*) from TblStudent)
    
    --计算年龄最大的
    select MAX(tsage) from TblStudent
    
    --计算年龄最小的
    select MIN(tsage) from TblStudent
    
    
    --计算平均值avg
    select avg(tsage) from TblStudent
    ------------聚合函数的一些其他问题-------------------
    --1.聚合函数不统计空值
    select * from TblStudent
    select count(tsage) from TblStudent
    select avg(tsage) from TblStudent  --avg()也是不统计空值的
    
    select sum(tsage) from TblStudent --sum()对于nulll值,认为是0
    --2.如果使用聚合函数的时候,没有手动group by分组,那么聚合函数会把整个表中的数据作为一组来统计。
  • 相关阅读:
    lua面向对象(定义与调用)
    luastring(字符串)
    luatable(表)
    lua面向对象(创建与实例化)
    pandas安装方法(常规安装失败解决方法)
    lua循环
    windows常用命令schtasks
    ios UI自动化 appium参数配置
    ios UI自动化环境配置
    jmeter进行websocket 通信
  • 原文地址:https://www.cnblogs.com/Strugglinggirl/p/7198523.html
Copyright © 2020-2023  润新知