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

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

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

```sql
select
    round(sum(isKeep) / count(1), 4) as avg_ret
from
    (
        select
            device_id,
            date,
            case
                when (
                    exists (
                        select
                            *
                        from
                            question_practice_detail d2
                        where
                            d2.device_id = qpd.device_id
                            and d2.date = date_add(qpd.date, interval 1 day)
                    )
                ) then 1
                else 0
            end as isKeep
        from
            question_practice_detail qpd
        group by
            device_id,
            date
    ) list;

```

全部评论

相关推荐

09-12 14:05
不想做程序员:招黑奴呢,我实习都6k,正式没1w我就不做程序员了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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