Query editor
WITH prices AS (SELECT date_trunc('day', "timestamp") AS day, symbol, priceFROM prices.dayWHERE blockchain = 'apechain' and symbol = 'APE' and "timestamp" >= TRY_CAST('2025-01-01' AS TIMESTAMP)ORDER BY day DESC),daily AS (SELECTdate_trunc('day', block_time) AS day,SUM(gas_used) AS total_gas_used,AVG(gas_used) AS avg_gas_used,SUM(CAST(gas_used AS DECIMAL(38, 0))* CAST(gas_price AS DECIMAL(38, 0))) / 1e18 AS total_usd_spentFROM apechain.transactionsGROUP BY 1)SELECtday,total_gas_used,round(avg_gas_used, 2) as avg_gas_used,round(total_usd_spent, 2) as total_usd_spent,round(SUM(total_usd_spent)OVER (ORDER BY dayROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW), 2) AS cumulative_usd_spentFROM (SELECTd.day,total_gas_used,avg_gas_used,total_usd_spent*p.price as total_usd_spentFROM prices as pJOIN(SELECTday,total_gas_used,avg_gas_used,total_usd_spentFROM dailyORDER BY day DESC) as dON p.day=d.day) as t1ORDER BY day DESC