Fred红叶 2020-04-09 00:38 采纳率: 66.7%
浏览 518
已采纳

Mysql:查询月流失用户数--紧急求解

需求:查询指定月份的流失用户数_
_

原表:f_user
图片说明

_

预期返回结果:
图片说明

_

user_id :用户唯一标识_

created_at 账号注册创建日期

update_at 最近一次登录日期

_

流失用户定义: 超过1个月未登录即为流失

  • 写回答

2条回答 默认 最新

  • bj_0163_bj 2020-04-09 09:22
    关注

    下面的a表你应该有的。或者你应该做一个连续月份的临时表。流失默认是到月底的。就是当月没有登录算流失

    select a.yf,
    count(case when substr(created_at,1,7)<=yf then id else null end) zongshu_ct,
    count(case when substr(created_at,1,7)=yf then id else null end) xinzeng_ct,
    count(case when substr(update_at,1,7)<yf then id else null end) liushi_ct
    
    from (
    select '2019-10' yf
    union all 
    select '2019-11' yf
    union all 
    select '2019-12' yf
    union all 
    select '2020-01' yf
    union all 
    select '2020-02' yf
    union all 
    select '2020-03' yf
    ) a 
    join f_user 
    on 1=1
    group by a.yf
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?