with uid_days_windows as ( select uid, max(day_diff) days_window from ( select uid, start_time, lag(start_time,1)over(partition by uid order by start_time) last_start_time, timestampdiff(day, lag(date_format(start_time,'%Y%m%d'),1)over(partition by uid order by start_time), date_format(start_time,'%...