Query editor
WITHbase AS (SELECTDATE_TRUNC('day', trades.block_time) AS block_date,concat(trades.token_sold_symbol,':',trades.token_sold_mint_address) as token,trades.token_sold_mint_address,(trades.token_sold_amount_raw/pow(10,ref.decimal)) as token_sold_amount,trades.amount_usd as amount_sold_usd,trades.amount_usd/(trades.token_sold_amount_raw/pow(10,ref.decimal)) as token_sell_price,(trades.amount_usd * pow(10,9))/(trades.token_sold_amount_raw/pow(10,ref.decimal)) as token_market_cap_sell,ROW_NUMBER() OVER (PARTITION BY trades.trader_id,trades.token_sold_symbol ORDER BY trades.block_time desc) AS row_num,trades.trader_id AS userAddress,trades.tx_id AS tx_hashFROMdex_solana.trades tradesleft join (select distinct token_mint_address,decimals as decimal from tokens_solana.fungible ) refon trades.token_sold_mint_address=ref.token_mint_addresswhere token_sold_symbol not IN ('SOL','USDC','USDT','weth','WBTC', 'JitoSOL','mSOL' , 'stSOL' ,'jito' , 'bSOL' , 'jSOL' , 'scnSOL' ,'mrgnLST','edgeSOL','pwrSOL' ,'superSOL' ,'jucySOL' ,'bonkSOL' ,'driftSOL' ,'compassSOL' ,'heliusSOL' ,'picoSOL' , 'jupSOL','','RAY','JLP','WETH', 'PYTH','HNT', 'JTO', 'BTC', 'ETH','PyUSD' )and trades.block_time >= TIMESTAMP '2024-06-01 00:00:00 'and trades.block_time <= TIMESTAMP '2025-02-10 00:00:00 'and trades.trader_id not in (select distinct user from dex_solana.bot_trades )--and trades.trader_id)selectuserAddress,token,max(block_date) as last_traded_date,sum(token_sold_amount) as token_sold_amount,sum(amount_sold_usd) as amount_sold_usd,sum(case when row_num = 1 then token_sell_price else 0 end ) as token_sell_price,sum(case when row_num = 1 then token_market_cap_sell*b.circulating_supply/(pow(10,9)) else 0 end ) as token_market_cap_sellfrom base as a left join query_4472239 as bon a.token_sold_mint_address=b.token_mint_addresswhere userAddress not in (select distinct user from dex_solana.bot_trades )group by 1,2