mysql中count统计不同数据出现次数
简单数据表 如图:
统计有多少个不同手机进行缴费
sql统计是使用count() 进行统计
- 在不考虑重复的情况下,统计手机数
select count( phone_id) from CM_LOG ;
- 结果 统计出来是3个(提示应该是2个的)
mysql> select count(phone_id) from CM_LOG;
±----------------+
| count(phone_id) |
±----------------+
| 3 |
±----------------+
1 row in set (0.00 sec)
正确统计方法要去重,即加 distinct
select count(distinct phone_id) from CM_LOG;
结果:
select count(distinct phone_id) from CM_LOG;
±-------------------------+
| count(distinct phone_id) |
±-------------------------+
| 2 |
±-------------------------+