Query editor
-- PM Category Overview – lifetime stats per narrative (OUTCOME-LEVEL naming)-- ALIGNED with heartbeat:-- 1) tx_hash-level aggregation for volume & trade counts WITH ECONOMIC VOLUME DEFINITION-- 2) unique_traders excludes infra (contract addresses)-- 3) condition_id join fixed for VARBINARY (market_trades) vs VARCHAR (market_details)---- IMPORTANT NAMING NOTE:-- "associated_outcomes" = COUNT(DISTINCT condition_id) touched by trades in that category-- This is NOT event-level market count (NegRisk markets can have many outcomes per event).WITH category_by_condition_small AS (-- Build a compact, one-category-per-condition mapping (condition_id stays VARCHAR here)WITH condition_tags AS (SELECTcondition_id,LOWER(array_join(array_distinct(array_agg(COALESCE(tags, ''))),',')) AS tags_lowerFROM polymarket_polygon.market_detailsWHERE condition_id IS NOT NULLGROUP BY condition_id)SELECTcondition_id,CASE-- 1) Politics & Elections (highest priority)WHEN tags_lower LIKE '%politic%'OR tags_lower LIKE '%election%'OR tags_lower LIKE '%president%'OR tags_lower LIKE '%senate%'OR tags_lower LIKE '%governor%'OR tags_lower LIKE '%primary%'OR tags_lower LIKE '%referendum%'THEN 'Politics & Elections'-- 2) SportsWHEN tags_lower LIKE '%sport%'OR tags_lower LIKE '%nba%'OR tags_lower LIKE '%nfl%'OR tags_lower LIKE '%mlb%'OR tags_lower LIKE '%nhl%'OR tags_lower LIKE '%cfb%'OR tags_lower LIKE '%ncaa%'OR tags_lower LIKE '%soccer%'OR tags_lower LIKE '%football%'OR tags_lower LIKE '%tennis%'OR tags_lower LIKE '%golf%'OR tags_lower LIKE '%ufc%'OR tags_lower LIKE '%mma%'OR tags_lower LIKE '%f1%'THEN 'Sports'-- 3) Crypto & Digital AssetsWHEN tags_lower LIKE '%crypto%'OR tags_lower LIKE '%bitcoin%'