题解 | #2021年11月每天新用户的次日留存率#

2021年11月每天新用户的次日留存率

https://www.nowcoder.com/practice/1fc0e75f07434ef5ba4f1fb2aa83a450

select 
    a.dt,
    ifnull(round(count(distinct b.uid)/count(a.uid),2),0) uv_left_rate
from 
    (
        select 
            uid,
            min(date(in_time)) dt
        from tb_user_log 
        group by uid
     ) a # 新用户首次登陆日期
left join 
    (
        select uid, date(in_time) dt from tb_user_log
        union          # 使用union去重合并登入登出表!!!!!!!!!!! 而不是用union all不去重
        select uid, date(out_time) from tb_user_log
	) b
on a.uid = b.uid
   and a.dt = date_sub(b.dt, INTERVAL 1 day) # 即在b汇总表中,筛选新用户次日登录的日期数据
where date_format(a.dt,'%Y-%m') = '2021-11'
group by a.dt
order by a.dt

全部评论

相关推荐

流浪的神仙:无恶意,算法一般好像都得9硕才能干算法太卷啦
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务