题解 | #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天;
#④根据日期分组,计算即可。

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-25 17:51
点赞 评论 收藏
分享
半解316:内容充实,细节需要修改一下。 1,整体压缩为一页。所有内容顶格。 2,项目描述删除,直接写个人工作量 修改完之后还需要建议,可以私聊
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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