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

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

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

select dt1,round( count(distinct if(datediff(dt2,dt1)=1 ,uid,null))/count(distinct if(uv=1,uid,null)),2)
from (
select  uid,dt as dt1,dense_rank() over(partition by uid order by dt) as uv,
lead(dt,1,dt) over(partition by uid order by dt) as dt2
from 
(
    select uid, date(in_time) as dt
    from tb_user_log
    union 
    select uid, date(out_time)
    from tb_user_log
)t2
#where substr(dt,1,7)='2021-11' 
#如果写在这里会排除第一天是上个月的情况,新用户就会定义错误 必须在排序后在写where
)t2
where uv=1 and substr(dt1,1,7)='2021-11'  
group by dt1

全部评论

相关推荐

07-09 15:14
南京大学 C++
点赞 评论 收藏
分享
头顶尖尖的程序员:我也是面了三四次才放平心态的。准备好自我介绍,不一定要背熟,可以记事本写下来读。全程控制语速,所有问题都先思考几秒,不要急着答,不要打断面试官说话。
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

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