题解 | #计算用户的平均次日留存率#

计算用户的平均次日留存率

https://www.nowcoder.com/practice/126083961ae0415fbde061d7ebbde453

WITH a AS (
  SELECT 
    distinct device_id, date
  FROM question_practice_detail
),
c as (
select *,RANK() OVER(PARTITION BY device_id ORDER BY date) AS rk,
    DATE_ADD(date, INTERVAL 1 DAY) AS d_plus_1
    from a
),
b AS (
  SELECT 
    *, 
    LEAD(date, 1) OVER(PARTITION BY device_id ORDER BY date) AS act_d
  FROM c
)
SELECT 
  COUNT(CASE WHEN act_d = d_plus_1 THEN 1 ELSE NULL END) / COUNT(1) AS avg_ret
FROM b;

全部评论

相关推荐

预计下个星期就能开奖吧,哪位老哥来给个准信
华孝子爱信等:对接人上周说的是这周
点赞 评论 收藏
分享
安静的垂耳兔在泡澡:ks已经第八次投递了,它起码挂了还让你再投,不错了
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务