/*
功能:用作统计使用,又称为聚合函数或统计函数或组函数

分类:
sum 求和、avg 平均值、max 最大值、min 最小值、count 计算个数

特点:
1.sum、avg一般用于处理数值型
max、min、count可以处理任何类型

2.以上分组函数都忽略null值

3.可以和distinct搭配实现去重的运算

4.count函数的单独介绍
一般使用count(*)用作统计行数

5.和分组函数一同查询的字段要求是group by后的字段
*/
image.png

1.简单的使用
SELECT SUM(salary) FROM employees;
SELECT AVG(salary) FROM employees;
SELECT MAX(salary) FROM employees;
SELECT MIN(salary) FROM employees;
SELECT COUNT(salary) FROM employees;
SELECT COUNT(commission_pct) FROM employees; #非空的个数
SELECT
SUM(salary) AS 和,AVG(salary) AS 平均,MAX(salary) AS 最大值
FROM
employees;


#2.参数支持哪些类型
SELECT SUM(last_name),AVG(last_name) FROM employees;
SELECT SUM(hiredate),AVG(hiredate) FROM employees;
SELECT MAX(last_name),MIN(last_name) FROM employees;
SELECT COUNT(last_name)FROM employees;

3.是否忽略null
SELECT
SUM(commission_pct),AVG(commission_pct),SUM(commission_pct)/35,SUM(commission_pct)/107
FROM
employees;

4.和distinct搭配
SELECT SUM(DISTINCT salary),SUM(salary) FROM employees;

5.count函数的详细介绍
SELECT COUNT(salary) FROM employees;
SELECT COUNT(*) FROM employees;
SELECT COUNT(1) FROM employees;

6.和分组函数一同查询的字段有限制
SELECT employee_id ,AVG(salary) FROM employees;