Query editor
-- 1) Aggregate gas usage and cost by dayWITH daily AS (SELECTdate_trunc('day', block_time) AS day,SUM(gas_used) AS total_gas_used,AVG(gas_used) AS avg_gas_used,-- sum of gas cost in APESUM(CAST(gas_used AS DECIMAL(38, 0))* CAST(gas_price AS DECIMAL(38, 0))) / 1e18 AS total_ape_spent,-- average gas cost in APEAVG(CAST(gas_used AS DECIMAL(38, 0))* CAST(gas_price AS DECIMAL(38, 0))) / 1e18 AS avg_ape_spentFROM apechain.transactionsWHERE block_time < current_dateGROUP BY 1)-- 2) Select daily data + a running (cumulative) total columnSELECTday,total_gas_used,avg_gas_used,total_ape_spent,avg_ape_spent,-- Cumulative (running) totalSUM(total_ape_spent)OVER (ORDER BY dayROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS cumulative_ape_spentFROM dailyORDER BY day DESC;