题解 | 最长连续登录天数

select user_id, max(consec_days) as max_consec_days
from
(
    select distinct user_id, count(*) over(partition by user_id,start_date) as consec_days
    from
    (
        select user_id, fdate, date_sub(fdate, interval rk day) as start_date
        from
        (
            select user_id, fdate, row_number() over(partition by user_id) as rk
            from 
            tb_dau as td
            where fdate >= "2023-01-01" and fdate <= "2023-01-31"
        ) as t1
    ) as t2
) as t3
group by user_id
order by user_id

全部评论

相关推荐

2025-11-28 13:56
已编辑
门头沟学院
所有好工作吻上来:最近可能压力比较大吧,面试的时候已经不屑于去说一些违心的话了,今天这场面试我真是没控制住啊,感觉我已经要发火了
实习学到最有价值的工作习...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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