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

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

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

select a.dt, round(count(distinct b.uid)/count(distinct a.uid),2)
from
(select uid, min(date_format(in_time,'%Y-%m-%d')) dt
from tb_user_log
group by uid) a
left join
(select uid, date_format(out_time,'%Y-%m-%d') dt
from tb_user_log
where date_format(out_time,'%Y-%m')='2021-11') b
on a.dt=date_sub(b.dt,interval 1 day)
and a.uid=b.uid
where datediff(a.dt,'2021-11-01')>=0
group by a.dt

# select datediff('2021-11-02','2021-11-01')
  • 找到第一次登录的日期
  • 找到登录的其他日期
  • 连接两个表
  • 然后继续聚合计算
  • 注意要以第一个表作为连接标准
  • 计数时要注意去重
全部评论

相关推荐

流浪的神仙:无恶意,算法一般好像都得9硕才能干算法太卷啦
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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