Query editor
WITH base_transactions AS (SELECT"from" AS user_address,block_timeFROM sei.transactionsWHERE success = TRUE),first_tx AS (SELECTuser_address,MIN(block_time) AS first_tx_timeFROM base_transactionsGROUP BY user_address),activity_windows AS (SELECTf.user_address,DATE_TRUNC('month', f.first_tx_time) AS cohort_month,MAX(CASE WHEN b.block_time >= f.first_tx_time + INTERVAL '15' DAY THEN 1 ELSE 0 END) AS retained_15d,MAX(CASE WHEN b.block_time >= f.first_tx_time + INTERVAL '30' DAY THEN 1 ELSE 0 END) AS retained_30d,MAX(CASE WHEN b.block_time >= f.first_tx_time + INTERVAL '60' DAY THEN 1 ELSE 0 END) AS retained_60d,MAX(CASE WHEN b.block_time >= f.first_tx_time + INTERVAL '90' DAY THEN 1 ELSE 0 END) AS retained_90dFROM first_tx fLEFT JOIN base_transactions bON f.user_address = b.user_addressGROUP BYf.user_address,DATE_TRUNC('month', f.first_tx_time)),cohort_retention AS (SELECTcohort_month,COUNT(DISTINCT user_address) AS new_users,100.0 * SUM(retained_15d) / COUNT(DISTINCT user_address) AS retention_15d_pct,100.0 * SUM(retained_30d) / COUNT(DISTINCT user_address) AS retention_30d_pct,100.0 * SUM(retained_60d) / COUNT(DISTINCT user_address) AS retention_60d_pct,100.0 * SUM(retained_90d) / COUNT(DISTINCT user_address) AS retention_90d_pctFROM activity_windowsGROUP BY cohort_month)SELECTcohort_month,retention_window,ROUND(retention_pct, 2) AS retention_pctFROM cohort_retentionCROSS JOIN UNNEST (ARRAY['15d', '30d', '60d', '90d'],ARRAY[retention_15d_pct,retention_30d_pct,retention_60d_pct,retention_90d_pct]) AS t(retention_window, retention_pct)GROUP BY cohort_month,retention_window,retention_pctORDER BY cohort_month, retention_window;