Query editor
with init as (select block_time as block_time,'uniswap_v3' as protocol, tx_from as userfrom uniswap_v3_ethereum.tradesunion allselect block_time as block_time,'uniswap_v3' as protocol, tx_to as userfrom uniswap_v3_ethereum.tradesunion allselect block_time as block_time,'sushiswap' as protocol, tx_from as userfrom sushiswap_ethereum.tradesunion allselect block_time as block_time,'sushiswap' as protocol, tx_to as userfrom sushiswap_ethereum.trades),total as (select date_trunc('week',block_time) as week,protocol,user,row_number() over (partition by user,protocol order by block_time) as row_num,date_diff('day',lag(block_time) over (partition by user,protocol order by block_time),block_time) as difffrom init),final as(select week,protocol,count(distinct user) as week_retention fromtotal where diff<=7 and row_num>=2group by 1,2)select * from final limit 10-- select new.week,week_retention,total_new_user,cast(week_retention*100 as real)/cast(total_new_user as REAL) as weekly_retention_rate-- from-- new-- left join-- final-- on new.week=final.week-- order by 1-- ,-- new as(-- select week,protocol,new_user,sum(new_user) over(partition by protocol order by week) as total_new_user from-- (select date_trunc('week',min_block_time) as week,protocol,count(distinct user) as new_user from-- (select user,protocol,min(block_time) as min_block_time from init group by 1,2) as p-- group by 1,2) q-- ),