聚合函数

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

聚合函数不能嵌套使用

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
# 在统计时字段内没有满足条件的数值只有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

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄