数据库:统计函数

COUNT(),统计表中记录的条数

AVG(),统计计算字段的平均值

SUM() ,统计字段的总和

MAX(),查询字段的最大值

MIN(),查询字段的最小值

1:count()

count(*),该种方式可以实现对表中记录进行统计,null和非null都要计算。 select count(*) number(别名)  from t_employee;查询到14条记录

count(field),该种方式可以实现对指定字段的记录进行统计,忽略null值 。select coun(comm) number from t_employee  where NOT comm =0;(要忽略到零值,要不然不符合实际)

2:AVG(),select AVG(comm奖金) average from t_employee where NOT comm=0; (要忽略零值)

3:sum(),select SUM(comm) sumvalue from t_employee where NOTcomm =0;

4:max,min(),select MAX(comm) maxval,MIN(comm) minval from t_employee;

如果表中没有任何数据记录,则count()函数返回0,而其他函数则返回null。

5:group by 分组查询,单纯的分组查询没意思,只会显示每一组的随机一条记录,


猜你喜欢

转载自blog.csdn.net/juleen890/article/details/80881600