Query editor
WITH monthly_token_volumes AS (-- Token volume and swap counts from tokenIn sideSELECTDATE_TRUNC('month', block_time) AS month,blockchain,token_sold_address AS token_address,SUM(amount_usd) AS volume,COUNT(*) AS swaps_countFROM (SELECT * FROM sushiswap_agg.tradesUNION ALLSELECT * FROM dune.sushi_labs.result_rp_trades_spellbook_pr)GROUP BY 1, 2, 3UNION ALL-- Token volume and swap counts from tokenOut sideSELECTDATE_TRUNC('month', block_time) AS month,blockchain,token_bought_address AS token_address,SUM(amount_usd) AS volume,COUNT(*) AS swaps_countFROM sushiswap_agg.tradesGROUP BY 1, 2, 3),aggregated_by_address AS (SELECTmonth,blockchain,token_address,SUM(volume) AS total_volume,SUM(swaps_count) AS total_swapsFROM monthly_token_volumesWHERE volume > 0GROUP BY month, blockchain, token_address),joined_with_tokens AS (SELECTa.month,a.blockchain,e.symbol,a.total_volume,a.total_swapsFROM aggregated_by_address aJOIN tokens.erc20 eON a.token_address = e.contract_addressAND a.blockchain = e.blockchain),aggregated_by_symbol AS (SELECTmonth,symbol,SUM(total_volume) AS total_volume,SUM(total_swaps) AS swapsFROM joined_with_tokensGROUP BY month, symbol),ranked AS (