Query editor
with timeframe as (selectcasewhen '{{Binance Interval}}' = 'monthly' then now() - interval '3' yearwhen '{{Binance Interval}}' = 'weekly' then now() - interval '2' yearwhen '{{Binance Interval}}' = 'daily' then now() - interval '1' yearend as start_date,casewhen '{{Binance Interval}}' = 'monthly' then 'month'when '{{Binance Interval}}' = 'weekly' then 'week'when '{{Binance Interval}}' = 'daily' then 'day'end as interval),Binance_evm as (select address fromquery_2296923where exchange = 'Binance'),Binance_btc as (SELECT address from query_2613158where exchange = 'Binance'),price as (select date_trunc('day',minute) as day, blockchain, symbol, contract_address, decimals,avg(price) as pricefrom prices.usdwhere minute >= (select start_date from timeframe)group by 1,2,3,4,5),erc20_outflow AS (SELECTDATE_TRUNC('day', evt_block_time) AS day,'ethereum' as blockchain,contract_address,SUM(cast(value as double)) AS amountFROMerc20_ethereum.evt_TransferWHEREevt_block_time >= (select start_date from timeframe)AND value IS NOT NULLAND("from" IN (select * from Binance_evm)AND NOT "to" IN (select * from Binance_evm))GROUP BY1,2,3union allSELECTDATE_TRUNC('day', evt_block_time) AS day,'arbitrum' as blockchain,contract_address,SUM(cast(value as double)) AS amountFROMerc20_arbitrum.evt_TransferWHEREevt_block_time >= (select start_date from timeframe)AND value IS NOT NULLAND("from" IN (select * from Binance_evm)AND NOT "to" IN (select * from Binance_evm))GROUP BY