Query editor
withdecimals as (select decimals,created_atfrom tokens_solana.fungible where token_mint_address = '{{token_address}}'),datasales AS (SELECTblock_time,DATE_TRUNC('{{period}}', block_time) AS date,trader_id AS wallet,-token_sold_amount as amount,amount_usd,'Sell' as actionFROM dex_solana.tradesWHEREtoken_sold_mint_address = '{{token_address}}'and block_time >= (select created_at from decimals)UNION ALLSELECTblock_time,DATE_TRUNC('{{period}}', block_time) AS date,trader_id AS wallet,token_bought_amount as amount,amount_usd,'Buy' as actionFROM dex_solana.tradesWHEREtoken_bought_mint_address = '{{token_address}}'and block_time >= (select created_at from decimals)),agg as (selectwallet,min(date) as join_date,sum(amount) as token_balance,sum(amount_usd) as trade_volume,sum(case when action = 'Buy' then amount_usd end) - sum(case when action = 'Sell' then amount_usd end) as profit,sum(case when action = 'Sell' then amount_usd end) as sell_volume,sum(case when action = 'Buy' then amount_usd end) as buy_volumefrom datasalesgroup by 1)select join_date,count(distinct wallet) as new_tradersfrom agg where join_date >= current_date - interval '3' monthgroup by 1order by join_date desc