Query editor
WITHdate_spine AS (SELECT cast(day as timestamp) AS dayFROM query_4063911WHERE day >= DATE '2024-08-28'),trade_data AS (SELECTDATE_TRUNC('day', block_time) AS day,project,blockchain,COALESCE(SUM(CASE WHEN blockchain = 'ethereum' AND token_bought_address = 0x2260fac5e5542a773aa44fbcfedf7c193bc2c599 THEN amount_usdWHEN blockchain = 'cronos' AND token_bought_address = 0x062e66477faf219f25d27dced647bf57c3107d52 THEN amount_usdWHEN blockchain = 'avalanche' AND token_bought_address = 0x50b7545627a5162f82a992c33b87adc75187b218 THEN amount_usdWHEN blockchain = 'optimism' AND token_bought_address = 0x68f180fcce6836688e9084f035309e29bf0a2095 THEN amount_usdWHEN blockchain = 'polygon' AND token_bought_address = 0x1bfd67037b42cf73acf2047067bd4f2c47d9bfd6 THEN amount_usdWHEN blockchain = 'arbitrum' AND token_bought_address = 0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f THEN amount_usd ELSE 0 END), 0) AS buy_volume,COALESCE(SUM(CASE WHEN blockchain = 'ethereum' AND token_sold_address = 0x2260fac5e5542a773aa44fbcfedf7c193bc2c599 THEN amount_usdWHEN blockchain = 'cronos' AND token_sold_address = 0x062e66477faf219f25d27dced647bf57c3107d52 THEN amount_usdWHEN blockchain = 'avalanche' AND token_sold_address = 0x50b7545627a5162f82a992c33b87adc75187b218 THEN amount_usdWHEN blockchain = 'optimism' AND token_sold_address = 0x68f180fcce6836688e9084f035309e29bf0a2095 THEN amount_usdWHEN blockchain = 'polygon' AND token_sold_address = 0x1bfd67037b42cf73acf2047067bd4f2c47d9bfd6 THEN amount_usdWHEN blockchain = 'arbitrum' AND token_sold_address = 0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f THEN amount_usd ELSE 0 END), 0) AS sell_volume,COALESCE(SUM(amount_usd), 0) AS total_volumeFROM dex.tradesWHEREblockchain IN ('ethereum', 'cronos', 'avalanche', 'optimism', 'polygon', 'arbitrum')AND ((blockchain = 'ethereum' AND (token_bought_address = 0x2260fac5e5542a773aa44fbcfedf7c193bc2c599 OR token_sold_address = 0x2260fac5e5542a773aa44fbcfedf7c193bc2c599))OR (blockchain = 'cronos' AND (token_bought_address = 0x062e66477faf219f25d27dced647bf57c3107d52 OR token_sold_address = 0x062e66477faf219f25d27dced647bf57c3107d52))OR (blockchain = 'avalanche' AND (token_bought_address = 0x50b7545627a5162f82a992c33b87adc75187b218 OR token_sold_address = 0x50b7545627a5162f82a992c33b87adc75187b218))OR (blockchain = 'optimism' AND (token_bought_address = 0x68f180fcce6836688e9084f035309e29bf0a2095 OR token_sold_address = 0x68f180fcce6836688e9084f035309e29bf0a2095))OR (blockchain = 'polygon' AND (token_bought_address = 0x1bfd67037b42cf73acf2047067bd4f2c47d9bfd6 OR token_sold_address = 0x1bfd67037b42cf73acf2047067bd4f2c47d9bfd6))OR (blockchain = 'arbitrum' AND (token_bought_address = 0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f OR token_sold_address = 0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f)))AND block_time >= DATE '2024-08-28'GROUP BY 1, 2, 3)SELECTd.day,t.blockchain,project,COALESCE(t.buy_volume, 0) AS buy_volume,COALESCE(t.sell_volume, 0) AS sell_volume,COALESCE(t.total_volume, 0) AS total_volumeFROMdate_spine dLEFT JOIN trade_data t ON d.day = t.dayWHERE d.day <= CURRENT_DATEORDER BY d.day, t.blockchain;