题解 | 最长连续登录天数

select 
    t2.user_id,
    max(consec_days) as max_consec_days
from
    (select
        user_id,
        count(*) as consec_days
    from (select 
            user_id,
            fdate,
            row_number()over(partition by user_id order by fdate) as "序号",
            date_sub(fdate,interval row_number()over(partition by user_id order by fdate) day) as "分组日期"
        from tb_dau
        where fdate between "2023-01-01" and "2023-01-31"
        group by user_id,fdate) as t 
    group by user_id,分组日期) as t2
group by t2.user_id

全部评论

相关推荐

点赞 评论 收藏
分享
09-17 10:53
四川大学 C++
牛客91242815...:会写标书没有任何卵用,鉴定为横向垃圾导师的受害者
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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