Query editor
WITHtron as (selectdate_trunc('day',evt_block_time) as time,sum(value/1e6) as usdFROM tether_tron.tether_usd_evt_transferwhere "to" IN (from_tron_address('TLumBJioNGzcxsEx7YtFzLpbYvdbaiKjAA'),from_tron_address('TP2Pph6xf9DJaBicvZQJj6BvmfGekjrGHn'))GROUP BY 1),eth as (SELECTdate_trunc('day',evt_block_time) as time,sum(value / 1e6) as usdFROM erc20_ethereum.evt_transferWHERE "from" = 0xE83aCd162cf418A7EB752a69381d73f23ee922E7AND contract_address in (0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48)GROUP BY 1),both as (SELECT * from tronUNION ALLSELECT * from eth),agg_data as (SELECTtime as time,sum(usd) as usdFROM bothwhere time > date('2023-08-01')GROUP BY 1),pat_agg as (select *,sum(usd) OVER (ORDER BY time) as total_usd,-DATE_DIFF('day', time, LAG(time) OVER (ORDER BY time)) AS count_dayFROM agg_data),avg_day as (select *,sum(count_day) OVER (ORDER BY time) as all_day,avg(count_day) OVER () as avg_dayfrom pat_agg)select *,total_usd/all_day as avg_day_usd,usd/count_day as avg_usdFROM avg_dayORDER BY time;