Query editor
WITH Outflows AS (-- Calculate the outflows from the first contract starting from 2024-10-03 16:00SELECTevt_block_time AS Time,value / 1e18 AS Outflow,NULL AS Inflow -- Add a NULL column to align with inflows for unionFROM erc20_ethereum.evt_TransferWHERE "from" = 0xb4bbf1edd67752a2ec01b35bc8053429457e0542AND evt_block_time >= TRY_CAST('2024-10-03 16:00:00' AS TIMESTAMP)),FirstOutflowTime AS (-- Get the first timestamp of the outflowsSELECT MIN(Time) AS FirstOutflowTimeFROM Outflows),Inflows AS (-- Calculate the inflows to the second contract starting from the first outflow timeSELECTevt_block_time AS Time,NULL AS Outflow,value / 1e18 AS InflowFROM erc20_ethereum.evt_TransferWHERE "to" = 0x4655b6a10c83d6beff1dc7116436cfd8b4f8d48aAND evt_block_time >= TRY_CAST('2024-10-03 16:00:00' AS TIMESTAMP)),ContractInflows AS (-- Calculate the inflows to the contract 0x8707f238936c12c309bfc2B9959C35828AcFc512 starting from 2024-10-03 16:00SELECTevt_block_time AS Time,value / 1e18 AS Inflow_ContractFROM erc20_ethereum.evt_TransferWHERE "to" = 0x8707f238936c12c309bfc2B9959C35828AcFc512AND evt_block_time >= TRY_CAST('2024-10-03 16:00:00' AS TIMESTAMP)),RunningTotals AS (-- Combine outflows and inflows and calculate running totalsSELECTTime,Outflow,Inflow,SUM(Outflow) OVER (ORDER BY Time ASC) AS Running_Total_Outflow,SUM(Inflow) OVER (ORDER BY Time ASC) AS Running_Total_InflowFROM (SELECT * FROM OutflowsUNION ALLSELECT * FROM Inflows) Combined),RunningContractInflows AS (-- Calculate the running total for the inflows to the specific contractSELECTTime,Inflow_Contract,SUM(Inflow_Contract) OVER (ORDER BY Time ASC) AS Running_Total_Contract_InflowsFROM ContractInflows),FullData AS (-- Use FULL JOIN to combine all timestamps from RunningTotals and RunningContractInflowsSELECTCOALESCE(RT.Time, RCI.Time) AS Time,