Query editor
with pares_legit as (select token_pair, blockchainfrom dex.tradeswhere project = 'uniswap'and block_time > now() - interval '90' dayand amount_usd < 1e8group by 1, 2having count(distinct taker) >= 50),par_dia as (selectdate_trunc('day', t.block_time) as dia,t.blockchain,t.token_pair,sum(t.amount_usd) as volume_usdfrom dex.trades tjoin pares_legit lon l.token_pair = t.token_pairand l.blockchain = t.blockchainwhere t.project = 'uniswap'and t.block_time > now() - interval '90' dayand t.block_time < current_dateand t.amount_usd < 1e8group by 1, 2, 3),limpo as (-- nenhum par legítimo faz > 5 bi num dia; o pico é preço quebrado em par cheio de botselect * from par_dia where volume_usd < 5e9),rank_chain as (select blockchain,row_number() over (order by sum(volume_usd) desc) as rkfrom limpogroup by 1)selectp.dia,case when r.rk <= 6 then p.blockchain else 'other' end as blockchain,sum(p.volume_usd) as volume_usdfrom limpo pjoin rank_chain r on r.blockchain = p.blockchaingroup by 1, 2order by 1, 3 desc