Query editor
WITH user_wallets AS (-- Get unique wallet addresses from materialized datasetSELECT DISTINCT user_addressFROM dune.serotonin_data.result_combined_midcap_dataset),-- Monthly trading volumes by traderhigh_volume_traders AS (SELECTDATE_TRUNC('month', block_time) AS trading_month,taker AS wallet_address,COUNT(DISTINCT tx_hash) AS trade_count,COUNT(DISTINCT token_pair) AS unique_pairs_traded,COUNT(DISTINCT blockchain) AS chains_count,ARRAY_AGG(DISTINCT blockchain) AS chains_used,SUM(amount_usd) AS monthly_volume_usdFROM dex.tradesWHERE taker IN (SELECT TRY_CAST(user_address AS varbinary) FROM user_wallets)AND block_time >= CURRENT_DATE - INTERVAL '1' YEARGROUP BY DATE_TRUNC('month', block_time), takerHAVING SUM(amount_usd) > 1500000 -- Filter for traders with >$1.5M monthly volume),-- Pre-calculate top tokens by trader and monthtrader_top_tokens AS (SELECTDATE_TRUNC('month', block_time) AS trading_month,taker AS wallet_address,token_bought_symbol,SUM(amount_usd) AS token_volume,ROW_NUMBER() OVER (PARTITION BY DATE_TRUNC('month', block_time), takerORDER BY SUM(amount_usd) DESC) AS token_rankFROM dex.tradesWHERE taker IN (SELECT wallet_address FROM high_volume_traders)AND block_time >= CURRENT_DATE - INTERVAL '1' YEARAND token_bought_symbol IS NOT NULLGROUP BY DATE_TRUNC('month', block_time), taker, token_bought_symbol),-- Pre-calculate top platforms by trader and monthtrader_top_platforms AS (SELECTDATE_TRUNC('month', block_time) AS trading_month,taker AS wallet_address,project,SUM(amount_usd) AS platform_volume,ROW_NUMBER() OVER (PARTITION BY DATE_TRUNC('month', block_time), takerORDER BY SUM(amount_usd) DESC) AS platform_rankFROM dex.tradesWHERE taker IN (SELECT wallet_address FROM high_volume_traders)AND block_time >= CURRENT_DATE - INTERVAL '1' YEARGROUP BY DATE_TRUNC('month', block_time), taker, project)-- Final outputSELECT