Query editor
withall_cex as (selectaddress,cex_name as namefrom addresses_ethereum.cexwhere cex_name in ('Binance', 'FTX', 'Coinbase', 'OKX', 'Huobi', 'Gate.io', 'Kraken', 'Bitfinex', 'KuCoin', 'Crypto.com', 'Gemini')unionselectaddress,cex_name as namefrom cex.addresseswhere cex_name in ('Binance', 'FTX', 'Coinbase', 'OKX', 'Huobi', 'Gate.io', 'Kraken', 'Bitfinex', 'KuCoin', 'Crypto.com', 'Gemini')),CEX as (selectDISTINCT address, name from all_cex),inflow as (SELECTdate_trunc('week', t."evt_block_time") AS time,c.name as exchange,SUM(CAST(t."value" AS DOUBLE)/1e18) AS amount_receivedFROM erc20_ethereum.evt_Transfer tleft join cex c on c.address = t."to"WHERE "to" in (select address from CEX)AND t.evt_block_time >= date('2017-01-01')AND contract_address in (/*0x2260fac5e5542a773aa44fbcfedf7c193bc2c599 , --WBTC0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2, --WETH*/0xB8c77482e45F1F44dE1745F52C74426C631bDD52 --BNB)GROUP BY 1, 2union allSELECTdate_trunc('week', t."evt_block_time") AS time,c.name as exchange,SUM(CAST(t."value" AS DOUBLE)/1e18) AS amount_receivedFROM erc20_bnb.evt_Transfer tleft join cex c on c.address = t."to"WHERE "to" in (select address from CEX)AND t.evt_block_time >= date('2017-01-01')AND contract_address in (/*0x7130d2a12b9bcbfae4f2634d864a1ee1ce3ead9c , --BTCB0x2170ed0880ac9a755fd29b2688956bd959f933f8, --ETH*/0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c --BNB)GROUP BY 1, 2),outflow as (SELECTdate_trunc('week', t."evt_block_time") AS time,c.name as exchange,SUM(CAST(t."value" AS DOUBLE)/1e18) AS amount_receivedFROM erc20_ethereum.evt_Transfer tleft join cex c on c.address = t."from"WHERE "from" in (select address from CEX)