Query editor
-- RM Internal: player CRM — one row per external wallet, single passWITH agg AS (SELECTwallet_addr,MAX(wallet) AS wallet,MIN(CAST(opened_at AS date)) AS first_seen,MAX(CAST(opened_at AS date)) AS last_seen,COUNT(DISTINCT CAST(opened_at AS date)) AS active_days,COUNT(DISTINCT date_trunc('week', opened_at)) AS active_weeks,COUNT(*) AS positions,COUNT_IF(role = 'detonator') AS det_positions,COUNT_IF(role = 'survivor') AS surv_positions,ROUND(SUM(deposited_usdc), 2) AS deposited_usdc,ROUND(SUM(pnl_usdc), 2) AS pnl_usdc,histogram(CAST(date_trunc('week', opened_at) AS date)) AS wk_hist,histogram(CAST(date_trunc('month', opened_at) AS date)) AS mo_histFROM query_8766977WHERE NOT is_teamGROUP BY wallet_addr)SELECTCASEWHEN last_seen >= current_date - INTERVAL '7' DAY THEN '1 active'WHEN last_seen >= current_date - INTERVAL '14' DAY THEN '2 cooling'WHEN active_days = 1 THEN '4 one-timer'ELSE '3 churned'END AS status,wallet,'0x' || lower(to_hex(wallet_addr)) AS wallet_full,first_seen, last_seen,date_diff('day', last_seen, current_date) AS days_since_last,active_days, active_weeks,positions, det_positions, surv_positions,deposited_usdc, pnl_usdc,array_join(transform(array_sort(map_keys(wk_hist)),k -> date_format(k, '%m-%d') || ':' || CAST(wk_hist[k] AS varchar)), ' ') AS weekly_activity,array_join(transform(array_sort(map_keys(mo_hist)),k -> date_format(k, '%b') || ':' || CAST(mo_hist[k] AS varchar)), ' ') AS monthly_activityFROM aggORDER BY status, deposited_usdc DESC