题解 | #2021年11月每天新用户的次日留存率#
2021年11月每天新用户的次日留存率
https://www.nowcoder.com/practice/1fc0e75f07434ef5ba4f1fb2aa83a450
select a.dt,
round(count(b.uid)/count(a.uid),2) as uv_left_rate
from
(select uid,min(date(in_time)) as dt from tb_user_log group by uid) a
left join (select b1.uid,date(b1.in_time) as dt from tb_user_log b1
union select b2.uid,date(b2.out_time) from tb_user_log b2) b
on a.uid=b.uid and datediff(b.dt,a.dt)=1
where date_format(a.dt,'%Y-%m')='2021-11'
group by a.dt
order by a.dt
