with swaps as
(
SELECT
date_trunc('month', block_timestamp) as date,
origin_from_address,
count(distinct tx_hash) as no_of_swaps,
row_number() over (partition by date_trunc('month', block_timestamp) order by count(distinct tx_hash) desc) as rank
from ethereum.core.ez_dex_swaps
group by 1,2
order by 1, 3 desc
)
SELECT
-- *,
date,
case when rank <= 10 then 'Top 10' else 'Others' end as category,
sum(no_of_swaps) as no_of_swaps
from swaps
group by 1,2
order by 1,3 desc