题解 | 最长连续登录天数

最长连续登录天数

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

#20230101-20230131
#max
#lianxudenglu 


with t1 as (
    select *,row_number() over (partition by td.user_id order by td.fdate) as rn
from tb_dau td),
t2 as(select *, date_sub(t1.fdate,interval rn day) as if_continue
from t1),
t3 as(
    select user_id, if_continue,count(*) as days_consec
    from t2
    where fdate between "2023-01-01" and "2023-01-31"
    group by user_id,if_continue
)
select user_id,max(days_consec) as max_consec_days
from t3
group by user_id


全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务