Query editor
with mau_detail as (with users as (select blockchain as chain, * from account_abstraction_erc4337.useropswhere block_time > timestamp '2023-03-01')select distinct date_trunc('month', block_time) as block_date,sender as userfrom users where block_time > now() - interval '12' month),mau_summary as (select block_date,count(*) as active_user_countfrom mau_detailgroup by 1order by 1),retention_user_summary as (select block_date,next_block_date,sum(retend) as retend_user_count,row_number() over (partition by block_date order by next_block_date) as month_difffrom (select prev.block_date,next.block_date as next_block_date,1 as retendfrom mau_detail previnner join mau_detail next on prev.block_date < next.block_date -- count all users active in next monthsand next.block_date < date_trunc('month', now()) -- exclude current monthand prev.user = next.user) tgroup by 1, 2),retention_count_summary as (select mau.block_date,active_user_count,sum(if(month_diff = 1, retend_user_count, 0)) as month1_retend_user_count,sum(if(month_diff = 2, retend_user_count, 0)) as month2_retend_user_count,sum(if(month_diff = 3, retend_user_count, 0)) as month3_retend_user_count,sum(if(month_diff = 4, retend_user_count, 0)) as month4_retend_user_count,sum(if(month_diff = 5, retend_user_count, 0)) as month5_retend_user_count,sum(if(month_diff = 6, retend_user_count, 0)) as month6_retend_user_count,sum(if(month_diff = 7, retend_user_count, 0)) as month7_retend_user_count,sum(if(month_diff = 8, retend_user_count, 0)) as month8_retend_user_count,sum(if(month_diff = 9, retend_user_count, 0)) as month9_retend_user_count,sum(if(month_diff = 10, retend_user_count, 0)) as month10_retend_user_count,sum(if(month_diff = 11, retend_user_count, 0)) as month11_retend_user_count,sum(if(month_diff = 12, retend_user_count, 0)) as month12_retend_user_countfrom mau_summary mauleft join retention_user_summary ret on mau.block_date = ret.block_datewhere mau.block_date < date_trunc('month', now()) -- exclude current monthgroup by 1, 2order by 1)