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

最长连续登录天数

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

全部评论

相关推荐

点赞 评论 收藏
分享
10-28 14:42
门头沟学院 Java
watermelon1124:因为嵌入式炸了
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务