with tab1 as (
select
min(BLOCK_TIMESTAMP::date) as date
,DELEGATOR_ADDRESS
,AMOUNT
from terra.core.ez_staking
where ACTION='Delegate'
group by 2,3)
select date
,case
when date>='2023-01-07' and date<='2023-01-13' then 'ONE WEEK BEFORE ANNOUNCE'
when date>='2023-01-14' and date<='2023-01-20' then 'ONE WEEK AFTER ANNOUNCE' end as time_period
,count(distinct DELEGATOR_ADDRESS) as "New Delegators"
,sum(AMOUNT) as "Delegate Amount"
,"Delegate Amount"/"New Delegators" as "Amount Per New User"
from tab1
where date>='2023-01-07'
and time_period is not null
group by 1,2