Query editor
With total_bought AS(SELECTtx_from,SUM(amount_usd) AS total_usd_b,COUNT(tx_hash) as Num_tx_bFROMdex.tradesWHEREblockchain = 'ethereum'AND token_bought_address = 0xf280B16EF293D8e534e370794ef26bF312694126-- AND--trader_id = 'DCAKuApAuZtVNYLk3KTAVW9GLWVvPbnb5CxxRRmVgcTr'GROUPBYtx_fromHAVINGMIN( block_time < TRY_CAST('2025-02-01 01:00' AS TIMESTAMP))), total_sold as(SELECTtx_from,SUM(amount_usd) as total_usd_s,COUNT(tx_hash) as Num_tx_sFROMdex.tradesWHEREtoken_sold_address = 0xf280B16EF293D8e534e370794ef26bF312694126ANDblockchain = 'ethereum'--AND--trader_id = 'DCAKuApAuZtVNYLk3KTAVW9GLWVvPbnb5CxxRRmVgcTr'GROUPBYtx_from)SELECTb.tx_from,s.total_usd_s,b.total_usd_b,b.Num_tx_b,s.Num_tx_s,(s.total_usd_s - b.total_usd_b) as pnlFROMtotal_bought bLEFT JOINtotal_sold sONb.tx_from = s.tx_fromOrderBYpnlDESC