--1:avg(distinct|all) 求平均
--all表示对所有的值求平均值,distinct只对不同的值求平均值
--all可以省略
select avg(sal) from scott.emp;
select avg(distinct sal) from scott.emp;
--2:max(distinct|all) 求最大值 distinct没有太大的用处
--求最大值,all表示对所有的值求最大值,distinct表示对不同的值求最大值,相同的只取一次
--(加不加查询结果一致,不知distinct有什么用途,不同于avg等聚合函数)
select max(distinct sal) from scott.emp;
select max(sal) from scott.emp
--3:min(distinct|all) distinct没有太大的用处
--求最小值,all表示对所有的值求最小值,distinct表示对不同的值求最小值,相同的只取一次
select min(sal) from scott.emp;
select min(distinct sal) from scott.emp;
--4:stddev(distinct|all) 求标准差, (多用)
--all表示对所有的值求标准差,distinct表示只对不同的值求标准差
select stddev(sal) from scott.emp;
select stddev(distinct sal) from scott.emp;
--5:variance(distinct|all) 求协方差 ['v?r??ns]:协方差 (多用)
--all表示对所有的值求协方差,distinct表示只对不同的值求协方差
select variance(sal) from scott.emp;
select variance(distinct sal) from scott.emp;
--6: sum(distinct|all) 求和
--all表示对所有值求和,distinct表示只对不同值求和(相同值只取一次)
select sum(sal) from scott.emp;
select sum(distinct sal) from scott.emp;
--7:count(distinct|all) --求记录、数据个数
--all对所有记录,数组做统计, distinct只对不同值统计(相同值只取一次)
select count(sal) from scott.emp;
select count(distinct sal) from scott.emp;
--8:median ['mid??n]:求中位数
select median(sal) from scott.emp;
select median(distinct sal) from scott.emp; --错误:distinct 选项在此函数中禁用。
--------------------------------------------------------------------------
参考地址:
https://www.cnblogs.com/kerrycode/archive/2011/04/26/2029875.html
更多优秀文章,请扫码关注个人微信公众号或搜索“程序猿小杨”添加。