zoukankan      html  css  js  c++  java
  • Oracle SQL函数之聚组函数

    AVG([distinct|all]x)
    【功能】统计数据表选中行x列的平均值。
    【参数】all表示对所有的值求平均值,distinct只对不同的值求平均值,默认为all
    如果有参数distinct或all,需有空格与x(列)隔开。
    【参数】x,只能为数值型字段
    【返回】数字值
    【示例】
    环境:
    create table table3(xm varchar(8),sal number(7,2));
    insert into table3 values('gao',1111.11);
    insert into table3 values('gao',1111.11);
    insert into table3 values('zhu',5555.55);
    commit;
    执行统计:
    select avg(distinct sal),avg(all sal),avg(sal) from table3;
    结果:  3333.33  2592.59  2592.59
    
    
    SUM([distinct|all]x)
    【功能】统计数据表选中行x列的合计值。
    【参数】all表示对所有的值求合计值,distinct只对不同的值求合计值,默认为all
    如果有参数distinct或all,需有空格与x(列)隔开。
    【参数】x,只能为数值型字段
    【返回】数字值
    【示例】
    执行统计:
    select SUM(distinct sal),SUM(all sal),SUM(sal) from table3;
    结果:  6666.66     7777.77     7777.77
    
    STDDEV([distinct|all]x)
    【功能】统计数据表选中行x列的标准误差。
    【参数】all表示对所有的值求标准误差,distinct只对不同的值求标准误差,默认为all
    如果有参数distinct或all,需有空格与x(列)隔开。
    【参数】x,只能为数值型字段
    【返回】数字值
    【示例】
    执行统计:
    select STDDEV(distinct sal),STDDEV(all sal),STDDEV(sal) from table3;
    结果:  3142.69366257674     2565.99863039714  2565.99863039714
    
    count(*|[distinct|all]x)
    【功能】统计数据表选中行x列的合计值。
    【参数】
    *表示对满足条件的所有行统计,不管其是否重复或有空值(NULL)
    all表示对所有的值统计,默认为all
    distinct只对不同的值统计,
    如果有参数distinct或all,需有空格与x(列)隔开,均忽略空值(NULL)。
    【参数】x,可为数字、字符、日期型及其它类型的字段
    【返回】数字值
    count(*)=sum(1)
    【示例】
    环境:
    create table table3(xm varchar(8),sal number(7,2));
    insert into table3 values('gao',1111.11);
    insert into table3 values('gao',1111.11);
    insert into table3 values('zhu',5555.55);
    insert into table3 values('',1111.11);
    insert into table3 values('zhu',0);
    commit;
    
    SQL> select * from table3;
    XM             SAL
    -------- ---------
    gao        1111.11
    gao        1111.11
    zhu        5555.55
               1111.11
    zhu           0.00
    
    执行统计:
    select count(*),count(xm),count(all xm),count(distinct sal),count(all sal),count(sal),sum(1) from table3;
    结果:  5   4  4  3   5   5  5
    
    
    MAX([distinct|all]x)
    【功能】统计数据表选中行x列的最大值。
    【参数】all表示对所有的值求最大值,distinct只对不同的值求最大值,默认为all
    如果有参数distinct或all,需有空格与x(列)隔开。
    【参数】x,可为数字、字符或日期型字段
    【返回】对应x字段类型
    SQL> select MAX(distinct sal),MAX(xm) from table3;
    MAX(DISTINCTSAL) MAX(XM)
    ---------------- --------
             5555.55 zhu
    
    MIN([distinct|all]x)
    【功能】统计数据表选中行x列的最大值。
    【参数】all表示对所有的值求最大值,distinct只对不同的值求最大值,默认为all
    如果有参数distinct或all,需有空格与x(列)隔开。
    【参数】x,可为数字、字符或日期型字段
    【返回】对应x字段类型
    注:字符型字段,将忽略空值(NULL)
    SQL> select MIN(distinct sal),MIN(xm),MIN(distinct xm),MIN(all xm) from table3;
    MIN(DISTINCTSAL) MIN(XM)  MIN(DISTINCTXM) MIN(ALLXM)
    ---------------- -------- --------------- ----------
                   0 gao      gao             gao
  • 相关阅读:
    Ubuntu 14.04/16.04/18.04安装最新版Eigen3.3.5
    Ubuntu16.04系统安装谷歌浏览器(Google chorm)
    Anaconda3(6)安装opencv
    Ubuntu 16.04 几个国内更新源
    Anaconda3(4-1)ubuntu1604安装pytorch
    Anaconda3(5-3)ubuntu1604安装pycharm
    无人机姿态定位
    Ubuntu16.04--安装Anaconda
    Airsim(1)安装配置win10-vs2015-cuda10-opencv394+扩展版版本+cmake
    cuda加速拼接
  • 原文地址:https://www.cnblogs.com/rusking/p/4414321.html
Copyright © 2011-2022 走看看