Query editor
WITH TradeDetails AS (-- 1. Join trades (volume data) with market details (resolution data)SELECTt.amount, -- The volume/cash of the traded.outcome -- The final market resolution ('Yes', 'No', 'Invalid', etc.)FROMpolymarket_polygon.market_trades tINNER JOINpolymarket_polygon.market_details d-- Join using the common market identifierON CAST(t.condition_id AS VARCHAR) = CAST(d.condition_id AS VARCHAR)),ResolvedVolume AS (-- 2. Calculate the total cash traded for each final resolutionSELECToutcome AS resolution,SUM(amount) AS total_volume_for_resolutionFROMTradeDetailsWHERE-- Filter only for markets that have a clear 'Yes' or 'No' resolutionoutcome IS NOT NULLAND outcome IN ('yes', 'no')GROUP BY1),TotalVolume AS (-- 3. Calculate the sum of all cash traded for all resolved 'Yes'/'No' marketsSELECTSUM(total_volume_for_resolution) AS grand_total_volumeFROMResolvedVolume)-- 4. Final Calculation: Calculate the cash-weighted percentageSELECTrv.resolution,rv.total_volume_for_resolution,-- Calculate the percentage: (Volume for Resolution / Grand Total Volume) * 100(rv.total_volume_for_resolution * 100.0) / tv.grand_total_volume AS percent_of_total_cash_tradedFROMResolvedVolume rv,TotalVolume tvORDER BYtotal_volume_for_resolution DESC