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

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

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

--统计2021年11月每天新用户的次日留存率(保留2位小数)
--注:
--次日留存率为当天新增的用户数中第二天又活跃了的用户数占比。
--如果in_time-进入时间和out_time-离开时间跨天了,在两天里都记为该用户活跃过,结果按日期升序。

-- 分析:
-- 1、求出每日的新增用户
-- 2、求出用户全量表(如果in_time-进入时间和out_time-离开时间跨天了,在两天里都记为该用户活跃过)
select first_login_time dt,
       round(count(distinct t2.uid)/count(t1.uid),2)
from
(
		求出每日的新增用户
    select uid,min(date(in_time)) first_login_time
    from tb_user_log
    group by uid
)t1
left join 
(
		求出用户全量表
    select uid,date(in_time) td
    from tb_user_log
    union 
    select uid,date(out_time)
    from tb_user_log
)t2
on t1.uid=t2.uid
and datediff(td,first_login_time)=1
group by first_login_time
having date_format(first_login_time,'%Y-%m')='2021-11'
order by dt;

全部评论

相关推荐

淬月星辉:专利是什么?至少描述一下吧,然后把什么计算机二级、普通话这种拉低格调的证书删掉,不然hr以为你没东西写
点赞 评论 收藏
分享
11-07 16:07
深圳大学 运营
前端飞升:学长,阿里不是卡双非吗,我深也能去吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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