问题描述
前边提问说查周流失率,就是上周登录的人在本周没登录这样的一个人数。select count(1) from (select distinct playerId from log_login l1 where week(now())-1=week(loginTime) and not exists(select distinct playerId from log_login l2 where l1.playerId = l2.playerId and week(NOW()) =week(loginTime)))t;现在又让我查各级别的周流失用户数比如说等级为2-10级这样一个等级段的人上周登录了在本周没登陆的人数。有好几个阶段 1,2-10,11-20,21-40,41-60,61-80,81-100.我加上leve>=x and level<=x。这几个查出来的数量比上周登录的总用户还要多!!不知道是我的sql语句错了,还是数据库的数据有问题。下面是我的sql语句:select count(distinct playerId) from log_login l1 where week(now())-1=week(loginTime) and level=1 and not exists(select distinct playerId from log_login l2 where l1.playerId = l2.playerId and week(NOW()) =week(loginTime) and level=1);
解决方案
select count(distinct playerId) from log_login l1 where week(now())=week(loginTime) and level=1 and not exists(select distinct playerId from log_login l2 where l1.playerId = l2.playerId and week(NOW()) -1=week(loginTime));去掉 and level=1 否则查询时会造成 很多not exists
解决方案二:
写得差不多了啊