今天头找到我,说:今天的净增用户数怎么回事啊,居然是0,今天总用户数是增加了的,领导问我我也不知道,小林你赶快查查数据库到底是怎么回事。我找到相关过程统计语句,做了以下工作排查,最终定位问题。一、统计到目前为止的用户数SELECT COUNT(DISTINCT a.username) FROM recharge_record a WHERE a.stat = 1;+--------------------------------------+| COUNT(DISTINCT a.username) |+--------------------------------------+| 1150 |+--------------------------------------+二、统计到今天凌晨为止的用户数mysql> SELECT -> COUNT(DISTINCT b.username) -> FROM -> recharge_record b -> WHERE b.stat = 1 -> AND b.ADDTIME+--------------------------------------+| COUNT(DISTINCT b.username) |+--------------------------------------+| 1130 |+--------------------------------------+三、当天净增用户mysql> SELECT -> COUNT(DISTINCT a.username) -> FROM -> recharge_record a -> WHERE a.stat = 1 -> AND a.username NOT IN -> (SELECT -> DISTINCT b.username -> FROM -> recharge_record b -> WHERE b.stat = 1 -> AND b.ADDTIME+--------------------------------------+| COUNT(DISTINCT a.username) |+--------------------------------------+| 0 |+--------------------------------------+居然是0看我下面的--sql区别mysql> SELECT -> COUNT(DISTINCT a.username) -> FROM -> recharge_record a -> WHERE a.stat = 1 -> AND a.username NOT IN -> (SELECT -> b.username -> FROM -> recharge_record b -> WHERE b.stat = 1 -> AND b.ADDTIME -> AND username IS NOT NULL) ;+--------------------------------------+| COUNT(DISTINCT a.username) |+--------------------------------------+| 21 |+--------------------------------------+恩这回不是0,为嘛是21?不要奇怪,刚才又偷偷的增加了一个用户这到底是为什么呢?不要问我 10-09 06:09