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

最长连续登录天数

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-14 16:13
已编辑
重庆科技大学 测试工程师
Amazarashi66:不进帖子我都知道🐮❤️网什么含金量
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务