题解 | 最长连续登录天数

最长连续登录天数

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

with temp0 as (
    select user_id,fdate,row_number()over(partition by user_id order by fdate asc) as rk
    from tb_dau td
    where fdate >= "2023-01-01" and fdate <= "2023-01-31"
), temp1 as (
    select user_id,adddate(fdate,interval -rk day) as new_date
    from temp0
), temp2 as (
    select user_id,count(*) as max_consec_days
    from temp1
    group by user_id,new_date
)

select user_id,max(max_consec_days) as max_consec_days
from temp2
group by user_id
order by user_id asc;

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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