Query editor
WITH first_appearance AS (SELECTmaker,MIN(evt_block_time) AS first_active_dateFROM probable_v1_bnb.ctfexchange_evt_orderfilledGROUP BY maker),user_d as( SELECTDATE_TRUNC('day', evt_block_time) AS date,a.maker,first_active_date,case when DATE_TRUNC('day', evt_block_time)=date(first_active_date) then 1 else 0 end as if_first_d,COUNT(DISTINCT evt_tx_hash) AS unique_ctf_txns,COUNT(DISTINCT evt_tx_from) AS unique_tx_from,COUNT(a.maker) AS ctf_dau,ROUND(SUM(CASEWHEN CAST(makerAssetId AS VARCHAR) = '0' THEN CAST(makerAmountFilled AS DOUBLE)WHEN CAST(takerAssetId AS VARCHAR) = '0' THEN CAST(takerAmountFilled AS DOUBLE)ELSE 0END)/ 1e18, 2) AS volumeFROM probable_v1_bnb.ctfexchange_evt_orderfilled aleft join first_appearance b on a.maker=b.makerGROUP BY 1,2,3,4)selectdate(first_active_date)first_dt,--cast(date_diff('day', date(first_active_date),date) as decimal)date_diff,count(distinct maker)new_user_cnt,--count(distinct case when date_diff('day', date(first_active_date),date)=1 then maker end)new_user_rentention_d1,--count(distinct case when date_diff('day', date(first_active_date),date)>0 and date_diff('day', date(first_active_date),date)<=3 then maker end)new_user_rentention_d3,--count(distinct case when date_diff('day', date(first_active_date),date)>0 and date_diff('day', date(first_active_date),date)<=7 then maker end)new_user_rentention_d7,--count(distinct case when date_diff('day', date(first_active_date),date)>0 and date_diff('day', date(first_active_date),date)<=15 then maker end)new_user_rentention_d15,round(count(distinct case when date_diff('day',first_active_date,now())>=1 and date_diff('day', date(first_active_date),date)=1 then maker end)*1.000/count(distinct maker)*1.000 ,2) as retention_d1,round(count(distinct case when date_diff('day',first_active_date,now())>=3 and date_diff('day', date(first_active_date),date)>0 and date_diff('day', date(first_active_date),date)<=3 then maker end)*1.000 /count(distinct maker)*1.000,2) as retention_d3,round(count(distinct case when date_diff('day',first_active_date,now())>=7 and date_diff('day', date(first_active_date),date)>0 and date_diff('day', date(first_active_date),date)<=7 then maker end)*1.000/count(distinct maker)*1.000,2) as retention_d7,round(count(distinct case when date_diff('day',first_active_date,now())>=15 and date_diff('day', date(first_active_date),date)>0 and date_diff('day', date(first_active_date),date)<=15 then maker end)*1.000/count(distinct maker)*1.000,2) as retention_d15,round(count(distinct case when date_diff('day',first_active_date,now())>=1 and date_diff('day', date(first_active_date),date)=1 then maker end)*1.000/count(distinct maker)*1.000 ,2) as retention_d1_d,round(count(distinct case when date_diff('day',first_active_date,now())>=3 and date_diff('day', date(first_active_date),date)>0 and date_diff('day', date(first_active_date),date)=3 then maker end)*1.000 /count(distinct maker)*1.000,2) as retention_d3_d,round(count(distinct case when date_diff('day',first_active_date,now())>=7 and date_diff('day', date(first_active_date),date)>0 and date_diff('day', date(first_active_date),date)=7 then maker end)*1.000/count(distinct maker)*1.000,2) as retention_d7_d,round(count(distinct case when date_diff('day',first_active_date,now())>=15 and date_diff('day', date(first_active_date),date)>0 and date_diff('day', date(first_active_date),date)=15 then maker end)*1.000/count(distinct maker)*1.000,2) as retention_d15_dfromuser_dgroup by 1order by 1