Query editor
withusers_db as (select distinctdate_trunc('month', block_time) as active_period,"from" as addressfrom polygon.transactionswhere block_time >= date_trunc('month',now()) - interval '1' year),inital_cohorts as (selectaddress,min(active_period) as initial_periodfrom users_dbgroup by 1),address_activity as (selectu.address,active_period,initial_period,round(cast(day(active_period - initial_period) as double) / 30, 0) as cohort_periodfrom users_db uleft join inital_cohorts ic on u.address = ic.address),retention as (selectinitial_period as cohort_id,cast(sum(case when cohort_period = 0 then 1 else null end) as double) as cohort_size,cast(sum(case when cohort_period = 1 then 1 else null end) as double) as month_1,cast(sum(case when cohort_period = 2 then 1 else null end) as double) as month_2,cast(sum(case when cohort_period = 3 then 1 else null end) as double) as month_3,cast(sum(case when cohort_period = 4 then 1 else null end) as double) as month_4,cast(sum(case when cohort_period = 5 then 1 else null end) as double) as month_5,cast(sum(case when cohort_period = 6 then 1 else null end) as double) as month_6,cast(sum(case when cohort_period = 7 then 1 else null end) as double) as month_7,cast(sum(case when cohort_period = 8 then 1 else null end) as double) as month_8,cast(sum(case when cohort_period = 9 then 1 else null end) as double) as month_9,cast(sum(case when cohort_period = 10 then 1 else null end) as double) as month_10,cast(sum(case when cohort_period = 11 then 1 else null end) as double) as month_11,cast(sum(case when cohort_period = 12 then 1 else null end) as double) as month_12from address_activitygroup by 1),retention_rates as (select--cohort_id,--cohort_size,avg(month_1 / cohort_size) as month_1,avg(month_2 / cohort_size) as month_2,avg(month_3 / cohort_size) as month_3,avg(month_4 / cohort_size) as month_4,avg(month_5 / cohort_size) as month_5,avg(month_6 / cohort_size) as month_6,avg(month_7 / cohort_size) as month_7,avg(month_8 / cohort_size) as month_8,avg(month_9 / cohort_size) as month_9,