select user_id, max(consec_days) as max_consec_days from ( select user_id, count(*) as consec_days from ( select fdate, user_id, ( dense_rank() over ( partition by user_id order by fdate ) ) as rk from tb_dau ) a group by user_id, (fdate - rk) ) b group by user_id