Query editor
-- Sonic ya agregado y rankeado, devuelto como blob CSV en 2 filas para poder leerlo de una-- (la cuota de datapoints de lectura de la API esta agotada este ciclo).-- Mismas columnas que csv/multichain-por-token.csv y por-par.csv. Filtro anclado, como el resto.with b as (select * from query_8220047 where anchored), x as (select 'total' as grain, cast(null as date) as month, token_in, token_out, sym_in, sym_out, swaps_clean, vol_in_usd_clean, vol_out_usd_clean from bunion all select 'xo_window', cast(null as date), token_in, token_out, sym_in, sym_out, swaps_clean, vol_in_usd_clean, vol_out_usd_cleanfrom b where month >= date '2026-01-01' and month < date '2026-08-01'union all select 'month', month, token_in, token_out, sym_in, sym_out, swaps_clean, vol_in_usd_clean, vol_out_usd_clean from b), legs as (select grain, month, token_in as tok, sym_in as sym, swaps_clean as sw_in, vol_in_usd_clean as v_in, 0 as sw_out, 0e0 as v_out from xunion allselect grain, month, token_out, sym_out, 0, 0e0, swaps_clean, vol_out_usd_clean from x), tk as (select grain, month, tok, max(sym) as sym, sum(sw_in) as sw, sum(v_in) as v_in, sum(sw_out) as sw_out, sum(v_out) as v_outfrom legs group by 1,2,3), tkr as (select tk.*, sum(v_in) over (partition by grain, month) as tot, row_number() over (partition by grain, month order by v_in desc, v_out desc) as rnkfrom tk), tkl as (select grain, month, rnk, coalesce(sym,'(sin symbol)') as label, '0x' || lower(tok) as addr, sw, v_in, tot, v_out, sw_outfrom tkr where rnk <= 20union allselect grain, month, 9999, '(otros)', '', sum(sw), sum(v_in), max(tot), sum(v_out), sum(sw_out)from tkr where rnk > 20 group by grain, month), pr as (select grain, month, least(coalesce(sym_in, token_in), coalesce(sym_out, token_out)) || ' / ' ||greatest(coalesce(sym_in, token_in), coalesce(sym_out, token_out)) as pair, sum(swaps_clean) as sw, sum(vol_in_usd_clean) as v_in, sum(vol_out_usd_clean) as v_outfrom x group by 1,2,3), prr as (select pr.*, sum(v_in) over (partition by grain, month) as tot, row_number() over (partition by grain, month order by v_in desc) as rnkfrom pr), prl as (select grain, month, rnk, pair, sw, v_in, tot, v_out from prr where rnk <= 15union allselect grain, month, 9999, '(otros)', sum(sw), sum(v_in), max(tot), sum(v_out) from prr where rnk > 15 group by grain, month)select 'tokens' as bloque, array_join(array_agg(line order by grain, month, rnk), chr(10)) as csvfrom (select grain, month, rnk, 'sonic,' || grain || ',' || coalesce(cast(month as varchar),'') || ',' || cast(rnk as varchar) || ',"' || label|| '",' || addr || ',' || cast(sw as varchar) || ',' || cast(round(v_in,2) as varchar) || ','|| cast(round(100.0 * v_in / nullif(tot,0), 4) as varchar) || ',' || cast(round(v_out,2) as varchar)|| ',' || cast(sw_out as varchar) as linefrom tkl)union all