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

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

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

with tb1 as(
    select uid, date(in_time) dt from tb_user_log
    union all
    select uid, date(out_time) dt from tb_user_log)

select tb3.dt, round(count(tb4.uid)/count(tb3.uid),2)
from
(select distinct uid, dt from(
select uid, dt, min(dt)over(partition by uid) min_dt from tb1) tb2
where dt=min_dt) tb3
left join 
(select distinct uid, dt from tb1) tb4
on tb3.uid=tb4.uid and datediff(tb4.dt,tb3.dt)=1
where date_format(tb3.dt,'%Y%m')='202111'
group by tb3.dt
order by tb3.dt

#思路:
#①因可能跨天活跃,所以将in_time和out_time先用union联立,形成表tb1备用;
#②找出新用户表,即min_dt=dt,形成tb3;
#③找出新用户次日活跃的数据,即将tb2与用户表左连接,加入连接条件:日期相差1天;
#④根据日期分组,计算即可。

全部评论

相关推荐

11-03 18:50
门头沟学院 Java
迷茫的大四🐶:问就是马上到,一周五天,6个月以上,全国可飞
点赞 评论 收藏
分享
LZStarV:冲就好了,就算真的是字节也冲,面评脏了大不了等三四个月就淡了,而且等到那个时候实力进步了选择还多,何必拘泥于字节
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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