Query editor
WITH all_swaps AS (SELECT * FROM dex.trades WHERE project_contract_address = {{pair_address}}),Buys AS (SELECTtx_from,SUM(amount_usd) AS total_buy,Sum(token_bought_amount_raw) / 1e9 as total_raw_buyFROMall_swapsWHEREtoken_bought_address = {{token_address}}GROUP BYtx_from),Sells AS (SELECTtx_from,SUM(amount_usd) AS total_sell,Sum(token_sold_amount_raw) / 1e9 as total_raw_sellFROMall_swapsWHEREtoken_bought_symbol = 'WETH'GROUP BYtx_from)SELECTb.tx_from,total_buy,total_sell,(total_sell - total_buy ) as profit,(total_raw_buy - total_raw_sell) / 1000 as left_to_sellFROMBuys bleft JOINSells s ON b.tx_from = s.tx_fromorder by profit desc;