Query editor
with buyers as (selectaddress, current_balance, gross_bought, first_buy, last_buy, on_address_retention_vs_gross_buysfrom query_8556828where first_buy is not nulland gross_bought > 0), dex_txs as (select distinct tx_hashfrom dex.tradeswhere blockchain = 'base'and block_date >= current_date - interval '30' dayand (token_bought_address = 0xc52aedec3374422d7510e294cfaa90799595cba3or token_sold_address = 0xc52aedec3374422d7510e294cfaa90799595cba3)), outflows as (selectbuyers.address, transfers.evt_block_time as block_time, cast(transfers.value as double) / 1e18 as amount, case when dex_txs.tx_hash is not null then 'dex' else 'transfer' end as outflow_typefrom buyersinner join erc20_base.evt_Transfer as transferson transfers."from" = buyers.addressand transfers.evt_block_time > buyers.first_buyleft join dex_txs on dex_txs.tx_hash = transfers.evt_tx_hashwhere transfers.contract_address = 0xc52aedec3374422d7510e294cfaa90799595cba3and transfers.evt_block_date >= current_date - interval '30' day), behavior as (selectbuyers.address, buyers.current_balance, buyers.gross_bought, buyers.first_buy, buyers.last_buy, buyers.on_address_retention_vs_gross_buys, sum(case when outflow_type = 'dex' and block_time <= first_buy + interval '1' day then amount else 0 end) as dex_sold_1d, sum(case when outflow_type = 'dex' and block_time <= first_buy + interval '3' day then amount else 0 end) as dex_sold_3d, sum(case when outflow_type = 'dex' and block_time <= first_buy + interval '7' day then amount else 0 end) as dex_sold_7d, sum(case when outflow_type = 'transfer' and block_time <= first_buy + interval '1' day then amount else 0 end) as transferred_out_1d, sum(case when outflow_type = 'transfer' and block_time <= first_buy + interval '3' day then amount else 0 end) as transferred_out_3d, sum(case when outflow_type = 'transfer' and block_time <= first_buy + interval '7' day then amount else 0 end) as transferred_out_7d, sum(case when outflow_type = 'dex' then amount else 0 end) as dex_sold_since_first_buy, sum(case when outflow_type = 'transfer' then amount else 0 end) as transferred_out_since_first_buyfrom buyersleft join outflows on outflows.address = buyers.addressgroup by 1, 2, 3, 4, 5, 6)select*, first_buy + interval '1' day <= now() as mature_1d, first_buy + interval '3' day <= now() as mature_3d, first_buy + interval '7' day <= now() as mature_7d, greatest(1 - dex_sold_1d / gross_bought, 0) as no_dex_sale_retention_1d, greatest(1 - dex_sold_3d / gross_bought, 0) as no_dex_sale_retention_3d