Query editor
with iv_cal AS (WITH day_seq AS (SELECT SEQUENCE(CAST('2024-07-27' AS TIMESTAMP),CAST(NOW() AS TIMESTAMP),INTERVAL '1' hour) AS day)SELECT days.day AS ttFROM day_seqCROSS JOIN UNNEST(day) AS days(day)),iv_usd0_in as (-- Inflows (positive)SELECTdate_trunc('hour', block_time) AS hh,b.address_name AS address_name,SUM(token_amt) AS token_amtFROM query_5315709 aLEFT JOIN query_5315129 bON b.address = a.to_addressWHERE token_name = 'TREE'AND tx_type <> 'burn' -- exclude burnsGROUP BY 1, 2UNION ALL-- Outflows (negative)SELECTdate_trunc('hour', block_time) AS hh,b.address_name AS address_name,SUM(-token_amt) AS token_amtFROM query_5315709 aLEFT JOIN query_5315129 bON b.address = a.from_addressWHERE token_name = 'TREE'AND tx_type <> 'mint' -- exclude mintsGROUP BY 1, 2)select a.tt,b.address_name,sum(b.token_amt) as token_amtfrom iv_cal aleft join iv_usd0_in b on b.hh <= a.ttgroup by 1,2order by 1 desc, 2