需求:查询指定月份的流失用户数_
_
原表:f_user
_
预期返回结果:
_
user_id :用户唯一标识_
created_at 账号注册创建日期
update_at 最近一次登录日期
_
流失用户定义: 超过1个月未登录即为流失
需求:查询指定月份的流失用户数_
_
原表:f_user
_
预期返回结果:
_
user_id :用户唯一标识_
created_at 账号注册创建日期
update_at 最近一次登录日期
_
流失用户定义: 超过1个月未登录即为流失
下面的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