题解 | 最长连续登录天数

最长连续登录天数

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

select
    user_id,
    max(count) as max_consec_days
from
(
select
    user_id,
    count(*) as count
from
    (
        select
            user_id,
            date_sub(fdate, interval xuhao day) as ds
        from
            (
            select
            user_id,
            fdate,
            row_number() over (partition by user_id order by fdate) as xuhao
            from tb_dau
            where
            year(fdate) = 2023
            and month(fdate) = 1
            group by user_id,fdate
            order by user_id
            ) a
    ) b
group by user_id,ds
) c
group by user_id
;

全部评论

相关推荐

2025-12-15 14:16
门头沟学院 Java
回家当保安:发offer的时候会背调学信网,最好不要这样。 “27届 ”和“28届以下 ”公司招聘的预期是不一样的。
实习简历求拷打
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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