Query editor
with trade as (selectblock_time, trader_id as trader, amount_usd as amount, token_bought_amount as token_bought, token_sold_amount as token_sold, casewhen token_bought_mint_address = 'AN4KfBxJ7VBZ4ijai2kn5F6CUfoi2ZEoD1jT52rJpump' then 'buy'when token_sold_mint_address = 'AN4KfBxJ7VBZ4ijai2kn5F6CUfoi2ZEoD1jT52rJpump' then 'sell'end as tradefrom dex_solana.tradeswhere token_bought_mint_address = 'AN4KfBxJ7VBZ4ijai2kn5F6CUfoi2ZEoD1jT52rJpump'or token_sold_mint_address = 'AN4KfBxJ7VBZ4ijai2kn5F6CUfoi2ZEoD1jT52rJpump'), pnl as (selectdistinct trader, coalesce(sum(casewhen trade = 'buy' then token_boughtend),0) as token_bought, sum(casewhen trade = 'sell' then token_soldend) as token_sold, coalesce(sum(casewhen trade = 'buy' then amountend),0) as buy, sum(casewhen trade = 'sell' then amountend) as sell, sum(casewhen trade = 'buy' then -amountwhen trade = 'sell' then amountend) as PnLfrom tradegroup by trader)selecttrader, token_bought, token_sold, buy, sell, PnL, case