Query editor
WITH trade_data AS (SELECTblock_date,token_pair,COALESCE(amount_usd, CASEWHEN token_bought_address = 0x8C907e0a72C3d55627E853f4ec6a96b0C8771145THEN token_bought_amount * priceELSE token_sold_amount * price END)AS trade_volume,project AS dexFROM dex.tradesJOIN (SELECTDATE_TRUNC('day', hour) AS block_date,AVG(median_price) AS priceFROM dex.pricesWHERE contract_address = 0x8C907e0a72C3d55627E853f4ec6a96b0C8771145GROUP BY 1) USING(block_date)WHERE block_time >= NOW() - INTERVAL '{{Number of days}}' day AND blockchain = 'bnb'AND (token_bought_address = 0x8C907e0a72C3d55627E853f4ec6a96b0C8771145 OR token_sold_address = 0x8C907e0a72C3d55627E853f4ec6a96b0C8771145))SELECTtoken_pair,dex,COUNT(*) AS trade_count,SUM(trade_volume) AS total_volumeFROM trade_dataGROUP BY 1, 2ORDER BY total_volume DESC;