题解 | #最长连续登录天数#

最长连续登录天数

https://www.nowcoder.com/practice/cb8bc687046e4d32ad38de62c48ad79b

select
    user_id,
    max(consec_days) as max_consec_days
from
    (
        select
            user_id,
            initial_day,
            count(1) as consec_days
        from
            (
                select
                    user_id,
                    date_sub(fdate, interval rk day) as initial_day
                from
                    (
                        select
                            user_id,
                            fdate,
                            row_number() over (
                                partition by
                                    user_id
                                order by
                                    fdate
                            ) as rk
                        from
                            tb_dau
                        where
                            date_format (fdate, '%Y%m%d') between 20230101 and 20230131
                    ) t1
            ) t2
        group by
            1,
            2
    ) t3
group by
    1

全部评论

相关推荐

不愿透露姓名的神秘牛友
11-22 12:00
点赞 评论 收藏
分享
评论
1
收藏
分享
牛客网
牛客企业服务