Query editor
-- 7d by chainWITHtradesPast7d AS (SELECTblock_date,blockchain,amount_usd,fee_usd,user,tx_hashFROMdune.bonkbot.result_dex_trading_bot_tradesWHEREisLastTradeInTransaction = trueAND block_time >= DATE_TRUNC('day', NOW()) - INTERVAL '14' day),firstUserOccurrences AS (SELECTuser,blockchain,MIN(block_date) AS firstTradeDateFROMtradesPast7dGROUP BYuser,blockchain),past7dSectorActivityByChainByDay AS (SELECTblock_date,tradesPast7d.blockchain,SUM(amount_usd) AS volumeUSD,SUM(fee_usd) AS botRevenueUSD,COUNT(DISTINCT (tradesPast7d.user)) AS numberOfUsers,COALESCE(COUNT(DISTINCT (firstUserOccurrences.user)), 0) AS numberOfNewUsers,COUNT(DISTINCT (tx_hash)) AS numberOfTradesFROMtradesPast7dLEFT JOIN firstUserOccurrences ON (tradesPast7d.user = firstUserOccurrences.userAND tradesPast7d.blockchain = firstUserOccurrences.blockchainAND tradesPast7d.block_date = firstUserOccurrences.firstTradeDate)GROUP BYblock_date,tradesPast7d.blockchainORDER BYblock_date ASC,volumeUSD DESC)SELECT*,volumeUSD / numberOfUsers AS averageVolumePerUserUSD,volumeUSD / numberOfTrades AS averageVolumePerTradeUSDFROMpast7dSectorActivityByChainByDayORDER BYblock_date ASC,volumeUSD DESC