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

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

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

#问题:统计2021年11月每天新用户的次日留存率(保留2位小数)
#1.2021年11月 每天
#2.新用户 次日留存率 当天新增的用户数中第二天又活跃了的用户数占比

select in_tm,round(count(distinct l_1)/count(uid),2) uv_left_rate
from
(select uid,in_tm,
         if((case when timestampdiff(day,in_tm,out_tm)>0 then 1 else 0 end)+(case when timestampdiff(day,in_tm,l_in_tm)>0 then 1 else 0 end)=0,null,uid) l_1
from
(select distinct uid, 
      date_format(in_time,'%Y-%m-%d') in_tm,
      date_format(out_time,'%Y-%m-%d') out_tm,
      lead(date_format(in_time,'%Y-%m-%d'),1,0) over(partition by uid) l_in_tm,
      case when date_format(in_time,'%Y-%m-%d') = min(date_format(in_time,'%Y-%m-%d'))over(partition by uid) then 1 else null end new
from tb_user_log)data1
where new is not null)data2
where year(in_tm)=2021 and month(in_tm)=11
group by in_tm

全部评论

相关推荐

在考古的丘比特很冷艳:[牛泪我横向一周多自动挂了,面试答的还行,感觉挂的莫名其妙
点赞 评论 收藏
分享
03-01 21:45
中北大学 golang
孤蓝长空:请你说一下为什么你用websocket而不是http,请你说一下什么是rpc,为什么用rpc,你的rpc的传输协议是JSON,xml还是什么 请你描述一下你的鉴权流程(完整的) 我问的是第二个项目,随便问的哈哈哈
开工第一帖
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

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