Query editor
with base as (selectcast(report_date as date) as report_date,asset_symbol as asset,case when network = 'ETH' then 'ERC' else network end as chain,direction,total_amountfrom dune.bpn_betterpaymentnetwork5188.dataset_ceffu_flow_daily_agg_dunewhere transaction_scope = 'ON_CHAIN'and asset_symbol in ('USDC', 'USDT'))selectreport_date,asset,chain,sum(total_amount) as total_tpv,sum(case when direction = 'deposit' then total_amount else 0 end) as on_chain_pay_in,sum(case when direction = 'withdrawal' then total_amount else 0 end) as on_chain_pay_outfrom basegroup by 1, 2, 3order byreport_date desc,case asset when 'USDC' then 1 when 'USDT' then 2 else 9 end,case chainwhen 'BSC' then 1when 'ERC' then 2when 'TRON' then 3when 'BASE' then 4when 'ARB' then 5when 'SOL' then 6when 'OPBNB' then 7else 99end