当前位置:Gxlcms > 数据库问题 > MySQL数据库:聚合函数的使用

MySQL数据库:聚合函数的使用

时间:2021-07-01 10:21:17 帮助过:4人阅读

聚合函数

max() 最大值
min() 最小值
avg() 平均值
sum() 求和
count() 符合条件数据的数目

聚合函数不能嵌套使用

# 在统计时字段内没有满足条件的数值只有count返回数值0或者其他,而其余四个聚合函数返回null;
# 对于聚合函数的参数,很多时候使用字段名来表示,那么这个时候,该字段内的null值不参与统计
count(*)
显示表中符合条件的信息数目,不考虑某字段出现null值
select count(cID),avg(elScore) from elogs;
select count(elNo),avg(elScore) from elogs;
select count(1),avg(elScore) from elogs;
select count(*),avg(elScore) from elogs;
转换编码
# 中文排序想要通过拼英排序的话需要转换编码
convert (tName using gbk)
去重复值
# distinct 后面如果有多个字段,则是针对这些字段值组合后的去重
select distinct sID from Elogs;
# 先去重,再统计
select count(distinct cID) from Elogs;

= 只有确定了一个值才能用 多条值用in

MySQL数据库:聚合函数的使用

标签:中文排序   聚合函数   参与   条件   聚合   class   参数   count()   mysql数据库   

人气教程排行