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

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

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

with T as( # 用户在某天活跃与下一次活跃

select uid, time,
    lead(time)over(partition by uid order by time) as next_time
    from (
        select uid,
        date(in_time) as time,
        1 as is_active
        from tb_user_log

        union

        select uid,
        date(out_time) as time,
        1 as is_active
        from tb_user_log
        order by uid, time
    )t
    
),
B as (  # 每日新用户有那些
    select 
    distinct   date(min(in_time)over(partition by uid)) as first_log,
    uid
    from tb_user_log
)

select
B.first_log as dt, 
round(count(T.next_time)/count(*) , 2) as uv_left_rate
from B
left join T
on B.first_log=T.time and B.uid=T.uid 
where date_format(B.first_log,'%Y-%m') = '2021-11' and (T.next_time is null or
timestampdiff(day, time, next_time)=1
)
group by dt
order by dt

全部评论

相关推荐

06-07 19:59
门头沟学院 C++
补药卡我啊😭:都快15年前的了还在11新特性
你的简历改到第几版了
点赞 评论 收藏
分享
06-07 17:17
嘉兴学院 教师
心爱的idea:你孩
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-25 17:13
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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