Query editor
withbase as (SELECTdistinct date_trunc('month', tx.block_time) as month,tx."from" as userFROM bnb.traces trLEFT JOIN bnb.transactions tx ON tx.hash = tr.tx_hashWHERE tr.to = 0x93C2260EE41b285C9Bbf98c6B9FFfbd3D62fcA36AND tr.successAND tr.block_time>= date('2023-03-01')),user_cohort as (--get the cohort start month for a specific user addressSELECTmin(month) as cohort,userFROM basegroup by 2),cohort_size as (SELECTcohort,count(*) as total_sizeFROM user_cohortgroup by 1),active_by_cohort as (SELECTcohort,month,row_number() OVER (partition by cohort order by month asc) as months,active_addressesFROM (SELECTu.cohort, b.month, count(*) as active_addressesFROM base bLEFT JOIN user_cohort u ON u.user = b.usergroup by 1,2)), retention_base as (SELECTa.cohort, total_size, map_agg(months, cast(active_addresses as double)/cast(total_size as double)) as retention_keyFROM active_by_cohort aLEFT JOIN cohort_size c ON c.cohort = a.cohortGROUP BY 1,2)SELECTsubstring(cast(cohort as varchar),1,10) as cohort, total_size