题解 | #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

全部评论

相关推荐

05-29 22:11
门头沟学院 Java
Elastic90:抛开学历造假不谈,这公司的招聘需求也挺怪的,Java开发还要求你有图文识别、移动端开发和c++的经验,有点逆天了。
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

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