聚集函数
1.AVG函数
SELECT AVG(col_name1) AS avg_col
FROM table_name;
返回特定行的平均值
SELECT AVG(col_name) AS avg_col
FROM table_name
WHERE condition;
2.COUNT()函数
确定表中行的数目或满足特定条件的行的数目,忽略NULL值
SELECT COUNT(*) AS num_col
FROM table_name;
其余函数不再赘述,使用方法相同
3.聚集不同的值
若有些行的值相同,不再重复计算,使用DISTINCT参数
SELECT AVG(DISTINCT col_name) AS avg_col
FROM table_name
WHERE condition
4.组合聚集函数
SELECT COUNT(*) AS num_col,
MIN(col_name) AS min_col,
MAX(col_name) AS max_col,
AVG(col_name) AS avg_col
FROM table_name;
分组函数
将数据分为多个逻辑组
1.创建分组
SELECT