Query editor
WITH user_monthly_volume AS (SELECTmaker,DATE_TRUNC('month', block_time) AS month,SUM(amount) AS monthly_volume,COUNT(*) AS monthly_trades,COUNT(DISTINCT condition_id) AS monthly_marketsFROM polymarket_polygon.market_tradesGROUP BY maker, DATE_TRUNC('month', block_time)),user_cumulative AS (SELECTmaker,month,monthly_volume,monthly_trades,monthly_markets,SUM(monthly_volume) OVER (PARTITION BY maker ORDER BY month) AS cumulative_volumeFROM user_monthly_volume),crossover_month AS (SELECTmaker,MIN(month) AS threshold_monthFROM user_cumulativeWHERE cumulative_volume >= 10000GROUP BY maker),user_periods AS (SELECTc.maker,c.month,c.monthly_volume,c.monthly_trades,c.monthly_markets,CASEWHEN c.month < x.threshold_month THEN 'Before $10K'WHEN c.month >= x.threshold_month THEN 'After $10K'END AS periodFROM user_cumulative cJOIN crossover_month x ON c.maker = x.maker),aggregated AS (SELECTperiod,ROUND(AVG(monthly_volume) / 2, 2) AS avg_volume,ROUND(AVG(monthly_trades), 1) AS avg_trades,ROUND(AVG(monthly_markets), 1) AS avg_marketsFROM user_periodsGROUP BY period)SELECT '1' AS metric_order, 'Avg Monthly Volume (USD)' AS "Metric", period AS "Period",avg_volume AS "Value"FROM aggregatedUNION ALLSELECT '2', 'Avg Monthly Trades', period,avg_tradesFROM aggregatedUNION ALL