题解 | #最长连续登录天数#
最长连续登录天数
https://www.nowcoder.com/practice/cb8bc687046e4d32ad38de62c48ad79b
# select
# from
select distinct user_id,const_num as "max_consec_days"
from(
select user_id, const_num, rank()over(partition by user_id order by const_num desc) as "fin_rank"
from(
select user_id, count(*) as "const_num"
from(
select user_id,fdate,ranking,(day(fdate)-ranking) as "cont"
from(
select user_id,fdate,row_number()over(partition by user_id order by fdate) as 'ranking'
from tb_dau
where fdate between '2023-01-01' and '2023-01-31'
)rank_t
)const_t
group by cont,user_id
)fina_t
)fina_t2
where fin_rank = 1
