SELECT * from
(SELECT *,
ROW_NUMBER() over (partition by day order by total_amt desc) as rn
from
(SELECT date(block_timestamp) as day, token_in, count(DISTINCT tx_hash) as total_txs,
sum(amount_out) as total_amt
from near.core.ez_dex_swaps
where token_out ilike 'wnear'
GROUP by 1,2 ))
where day >= '2022-01-01' and rn < 4