题解|25. 6月2日的T+1日留存
6月2日的T+1日留存
明确题意:
统计6月2日的T+1日留存
问题拆解:
- 筛选20210602登录的用户唯一ID。知识点:where、distinct
- 筛选20210603登录的用户唯一ID。知识点:where、distinct
- 统计0602登录用户在0603的登录状态。知识点:left join
- 计算0602的用户在0603的留存率。知识点:count
- 保留小数位数。知识点:round
代码实现:
select round(count(login_0603) / count(login_0602), 4) as avg_ret
from (
select distinct user_id, 1 as login_0602, login_0603
from logintb
left join (
select distinct user_id, 1 as login_0603
from logintb
where login_date='2021-06-03'
) as t_login_3
using (user_id)
where login_date='2021-06-02'
) as login_02_03