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

最长连续登录天数

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


select
          user_id
          ,count_d as max_consec_days
from
(
select
            user_id
            ,count_d
            ,dense_rank() over (partition by user_id order by count_d desc) as _rank
from
(
select
            user_id
            ,(fdate - rank_) as fd
            ,count(*) as count_d
from
(
select
            user_id
            ,fdate
            ,row_number() over (partition by user_id order by fdate ) as rank_
from
            tb_dau
group by
            1,2

having
            fdate between '2023-01-01' and '2023-01-31'
)   t1
group by    
            1,2
)   t2
group by
            1,2
)   t3
WHERE
        _rank = 1     

全部评论

相关推荐

11-13 11:12
门头沟学院 Java
咩咩子_:专业技能写上面 项目往下放,如果可以的话改一下学校最好
点赞 评论 收藏
分享
怎么起名字:学历不足,
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务