题解 | 最长连续登录天数

最长连续登录天数

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

with first as (
select
   distinct user_id,fdate,row_number() over (partition by user_id order by fdate asc) as rn
from tb_dau
where fdate between '2023-01-01' and '2023-01-31'

),
days as (select user_id,
                fdate,
                rn,
                date_sub(fdate, interval rn day)     as day
         from first)
        
,
day_cnt as (
select user_id,
    day,
      count(day) cnt
from days
group by user_id,day
)
select user_id,max(cnt)  as max_consec_days
from day_cnt
group by user_id
;

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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