with stake as ( select date(block_timestamp) as date, case when date >= '2023-01-15' then 'After Terra Station'
when date = '2023-01-14' then 'Launch Day' else 'Before Terra Station' end as date_type,VALIDATOR_LABEL,
count(DISTINCT(tx_id)) as total_tx, sum(amount) as amounts
from terra.core.ez_staking
where action = 'Delegate'
and validator_label is not null
group by 1,2,3)
select VALIDATOR_LABEL, date_type, avg(total_tx) as avg_tx, avg(amounts) as avg_amount,
rank() over (partition by date_type order by avg_amount desc) as rank
from stake
where date >= CURRENT_DATE - 45
group by 1,2
qualify rank <= 5