今天头找到我,说:今天的净增用户数怎么回事啊,居然是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 < '2015-06-02 00:00:00';
+--------------------------------------+
| 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< '2015-06-02 00:00:00');
+--------------------------------------+
| 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 < '2015-06-02 00:00:00'
-> AND username IS NOT NULL) ;
+--------------------------------------+
| COUNT(DISTINCT a.username) |
+--------------------------------------+
| 21 |
+--------------------------------------+
恩这回不是0,为嘛是21
?
不要奇怪,刚才又偷偷的增加了一个用户
这到底是为什么呢?不要问我
阅读(1297) | 评论(0) | 转发(0) |