无敌小贱 2013-05-02 16:17 采纳率: 0%
浏览 786
已采纳

mysql查询周留存

出来了一个,但总是感觉不对。贴上来看看,如果不对应该怎么写?我要查询本周登录下周不再登录的用户数量。
select count(distinct playerId) from log_login l1 where week(now())-1=week(loginTime) and exists(select 1 from log_login l2 where l1.playerId = l2.playerId and week(NOW())=week(loginTime));

  • 写回答

2条回答

  • jinnianshilongnian 2013-05-02 17:14
    关注

    select count(distinct playerId) from log_login l1 where week(now())=week(loginTime) and exists(select 1 from log_login l2 where l1.playerId = l2.playerId and week(NOW()) - 1=week(loginTime));

    留存率是:上周登录了 这周也登录了 你写的按理说没错

    我要查询本周登录下周不再登录的用户数量。 不是下周 而是上周
    select count(distinct playerId) from log_login l1 where week(now())-1=week(loginTime) and exists(select 1 from log_login l2 where l1.playerId = l2.playerId and week(NOW())=week(loginTime));

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?