with Date(now()) as end_date,
    '2021-08-20' as start_date
select
       login_date, days, count() as num
from (
      select `#account_id`, arrayJoin(log2) log3, log3.1 as login_date, log3.2 as days
      from (select `#account_id`,
                   login_date,
                   arrayMap((x, y)->dateDiff('day', x, y) - 1, arraySlice(login_date, 1, length(login_date) - 1),
                            arraySlice(login_date, 2, length(login_date) - 1))                        log1,
                   arrayMap((x, y)-> (x, y), arraySlice(login_date, 1, length(login_date) - 1), log1) log2

            from (select `#account_id`, arraySort(groupArray(date)) login_date
                  from (
                        with toDate(addHours(`#event_time`, 8)) as date
                        select date, `#account_id`
                        from zhengba.event
                        where `#event_name` = 'login'
                          and date >= start_date
                          and date <= end_date
                        group by date, `#account_id`
                           )
                  group by `#account_id`
                  having length(login_date) > 1)))
group by login_date,days
order by  login_date,days