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

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

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

聚合函数

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

聚合函数不能嵌套使用

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

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

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

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

人气教程排行