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