Query editor
WITHtrades AS (SELECT*,date_trunc('day', block_time) AS block_dateFROM/* Trades */query_4086080),marketLeaderboard AS (SELECTmarket,marketType,SUM(sizeDelta) AS volumeUSD,SUM(fee) + SUM(fundingFee) + SUM(borrowFee) AS totalFeesUSD,SUM(fee) AS feesUSD,SUM(fundingFee) AS fundingFeesUSD,SUM(borrowFee) AS borrowFeesUSD,COUNT(DISTINCT (trades.user)) AS numberOfUsers,COUNT(DISTINCT (tx_hash)) AS numberOfTrades,COUNT(DISTINCT (IF(direction = 'Long', tx_hash, NULL))) AS numberOfLongs,COUNT(DISTINCT (IF(direction = 'Short', tx_hash, NULL))) AS numberOfShorts,COUNT(DISTINCT (posId)) AS numberOfPositions,COUNT(DISTINCT (IF(type = 'Liquidate', tx_hash, NULL))) AS numberOfLiquidationsFROMtradesWHEREmarket IS NOT NULLGROUP BYmarket,marketType)SELECTRANK() OVER (ORDER BYvolumeUSD DESC) AS rank,*FROMmarketLeaderboardORDER BYvolumeUSD DESC