Query editor
WITH user_monthly AS (SELECTDATE_TRUNC('month', block_time) AS month,sender,COUNT(*) AS txns,SUM(amount_usd) AS spend_usdFROM query_5365290WHERE amount_usd > 0GROUP BY 1, 2),user_segments AS (SELECTmonth,sender,txns,spend_usd,CASEWHEN txns >= 20 THEN 'Power (20+ txns)'WHEN txns >= 8 THEN 'Regular (8-19 txns)'WHEN txns >= 3 THEN 'Occasional (3-7 txns)'ELSE 'Light (1-2 txns)'END AS frequency_segment,CASEWHEN txns >= 20 THEN 1WHEN txns >= 8 THEN 2WHEN txns >= 3 THEN 3ELSE 4END AS freq_order,CASEWHEN spend_usd >= 1000 THEN 'High ($1000+)'WHEN spend_usd >= 250 THEN 'Medium ($250-999)'WHEN spend_usd >= 50 THEN 'Low ($50-249)'ELSE 'Micro (< $50)'END AS value_segment,CASEWHEN spend_usd >= 1000 THEN 1WHEN spend_usd >= 250 THEN 2WHEN spend_usd >= 50 THEN 3ELSE 4END AS val_orderFROM user_monthly)SELECTmonth,-- Frequency segmentsfrequency_segment,freq_order,value_segment,val_order,COUNT(DISTINCT sender) AS users,SUM(txns) AS total_txns,ROUND(SUM(spend_usd), 2) AS total_spend_usd,ROUND(AVG(spend_usd), 2) AS avg_spend_per_user,ROUND(100.0 * COUNT(DISTINCT sender) / SUM(COUNT(DISTINCT sender)) OVER (PARTITION BY month), 1) AS pct_of_usersFROM user_segmentsGROUP BY 1, 2, 3, 4, 5ORDER BY month, freq_order, val_order