Oracle支持许多内建的聚合函数,可以对数据进行统计汇总。常用的聚合函数如下:
- COUNT:统计行数
- SUM:求和
- AVG:平均值
- MAX:最大值
- MIN:最小值
- STDDEV:标准差
- VARIANCE:方差
例如:
-- 统计employees表的行数
SELECT COUNT(*) FROM employees;
-- 求employees表的工资总和
SELECT SUM(salary) FROM employees;
-- 求employees表的工资平均值
SELECT AVG(salary) FROM employees;
-- 求employees表的最高工资
SELECT MAX(salary) FROM employees;
-- 求employees表的最低工资
SELECT MIN(salary) FROM employees;
-- 求employees表工资的标准差
SELECT STDDEV(salary) FROM employees;
-- 求employees表工资的方差
SELECT VARIANCE(salary) FROM employees;
聚合函数也可以和GROUP BY语句一起使用,对组内数据进行汇总:
-- 根据部门汇总每个部门的工资总和
SELECT department_id, SUM(salary)
FROM employees
GROUP BY department_id;
-- 根据部门汇总每个部门的工资平均值
SELECT department_id, AVG(salary)
FROM employees
GROUP BY department_id;
标签:salary,聚合,函数,--,employees,department,id,SELECT
From: https://www.cnblogs.com/suixingc/p/17554700.html