题解 | #最长连续登录天数#
最长连续登录天数
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