版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013003827/article/details/68108332
11.1 统计数据记录条数—-count()
统计函数count()用来实现统计数据记录条数。
- count(*):该方式可以实现对表中记录进行统计,不管表字段中包含的是NULL值还是非NULL值
- count(field):该方式可以实现对指定字段的记录进行统计,在具体统计时将忽略NULL值
例:有如下employye表
mysql> select count(*) number from employee; // 统计雇员表的记录数
mysql> select count(bonus) number from employee; //统计领取奖金的员工数目
等价于:
mysql> select count(bonus) number from employee where not bonus=0;
11.2 统计计算平均值—avg()
mysql> select avg(salary) average_salary from employee; //统计公司员工平均薪水
11.3 统计计算求和—sum()
mysql> select sum(salary) sum_salary from employee; // 统计员工每月薪水总和
11.4 统计计算最大值和最小值—max()和min()
mysql> select max(salary) max_salary, min(salary) min_salary from employee;