Query editor
WITH first_hold AS (SELECT"to" AS address,MIN(DATE_TRUNC('month', evt_block_time)) AS cohort_monthFROM erc20_ethereum.evt_TransferWHERE contract_address = 0xa12cc123ba206d4031d1c7f6223d1c2ec249f4f3AND "to" != 0x0000000000000000000000000000000000000000GROUP BY 1),monthly_balances AS (SELECTDATE_TRUNC('month', evt_block_time) AS month,"to" AS address,SUM(CAST(value AS DOUBLE)) AS inflowFROM erc20_ethereum.evt_TransferWHERE contract_address = 0xa12cc123ba206d4031d1c7f6223d1c2ec249f4f3AND "to" != 0x0000000000000000000000000000000000000000GROUP BY 1,2UNION ALLSELECTDATE_TRUNC('month', evt_block_time) AS month,"from" AS address,-SUM(CAST(value AS DOUBLE)) AS inflowFROM erc20_ethereum.evt_TransferWHERE contract_address = 0xa12cc123ba206d4031d1c7f6223d1c2ec249f4f3AND "from" != 0x0000000000000000000000000000000000000000GROUP BY 1,2),cumulative AS (SELECTmb.month,mb.address,fh.cohort_month,SUM(mb.inflow) OVER (PARTITION BY mb.address ORDER BY mb.month) AS cum_balanceFROM monthly_balances mbJOIN first_hold fh ON mb.address = fh.address),cohort_sizes AS (SELECT cohort_month, COUNT(DISTINCT address) AS cohort_sizeFROM first_holdGROUP BY 1),retention AS (SELECTc.cohort_month,DATE_DIFF('month', c.cohort_month, c.month) AS months_since_acquisition,COUNT(DISTINCT CASE WHEN c.cum_balance > 0 THEN c.address END) AS retained_holders,cs.cohort_sizeFROM cumulative cJOIN cohort_sizes cs ON c.cohort_month = cs.cohort_monthWHERE DATE_DIFF('month', c.cohort_month, c.month) >= 0GROUP BY 1, 2, 4)SELECTcohort_month,months_since_acquisition,