Query editor
-- Columns-- cohort: min(month)-- month: the month of user's NFT trade-- months: row_number PARTITION cohort ORDER month ascWITHbase as (SELECT distinct month, userFROM(SELECTdate_trunc('month', block_time) as month, buyer as userFROM nft.tradesWHERE blockchain = '{{W7_blockchain}}'AND project = '{{W7_project}}'UNION ALL -- if select both buyer,seller in a single SELECT clause, the result will be three colsSELECTdate_trunc('month', block_time) as month, seller as userFROM nft.tradesWHERE blockchain = '{{W7_blockchain}}'AND project = '{{W7_project}}')), user_cohort as( -- assign each user to a cohortSELECTmin(month) as cohort, userFROM baseGROUP BY 2), cohort_size as( -- get total size of cohortsSELECTcount(*) as total_size, cohortFROM user_cohortGROUP BY 2), active_by_cohort as(SELECTcohort, month, row_number() over (partition by cohort order by month asc) as months, active_addressesFROM (SELECTuc.cohort, b.month, count(*) as active_addressesFROM base bLEFT JOIN user_cohort uc ON uc.user = b.userGROUP BY 1, 2)), retention_base as ( -- for a given month, which cohort address were active / total size of cohort size