Query editor
with base_table as (selectevt_block_time,"to",cast(id as varchar) as id, sum(cast(value as double)) as amtfrom erc1155_polygon.evt_TransferSinglewhere contract_address= 0x0B5cfed5efB6f831468B8b5b5321B71825a2AEe0and "from" = 0x0000000000000000000000000000000000000000and 1 <= {{Synchronize}}and cast(id as varchar) !='3' and cast(id as varchar) !='100000' --exclude retriever drone and Balanced Drone Chassis - Limited Editionand evt_block_time >= cast('2022-12-08' as timestamp) --contract creation dategroup by 1,2,3union allselect evt_block_time,"to",cast(id as varchar) as id,sum(cast(value as double)) as amtfrom(select *from erc1155_polygon.evt_TransferBatchcross join unnest("ids","values") as tbl(id,value)where contract_address=0x0B5cfed5efB6f831468B8b5b5321B71825a2AEe0and "from" = 0x0000000000000000000000000000000000000000and evt_block_time >= cast('2022-12-08' as timestamp) --contract creation dateand cast(id as varchar) !='3' and cast(id as varchar) !='100000' --exclude retriever drone and Balanced Drone Chassis - Limited Edition) sgroup by 1,2,3), stacking as(-- you technically can use union all but its more precise with a union-- there is a small of txns that have the same address for buyer and seller-- trade off here is query speedselectdistinct "to" as address,evt_block_timefrom base_table),user_cohorts as ( -- track when addresses first appearedSELECT distinct "to" as address, min(date_trunc('month', evt_block_time)) as cohortMonthFROM base_tablegroup by 1),following_months as ( -- join the addresses against when they first appeared and subtract the time diff where they appeared subsequentlySELECT stacking.address, date_diff('month', uc.cohortMonth, date_trunc('month', evt_block_time)) as month_numberFROM stackingLEFT JOIN user_cohorts ucON stacking.address = uc.addressGROUP BY 1,2),cohort_size as ( -- count the number of total users of a monthSELECT uc.cohortMonth as cohortMonth, count(*) as num_usersFROM user_cohorts ucGROUP BY 1ORDER BY cohortMonth),retention_table as ( -- for the given month, count the number of times the address had appeared for x times