Query editor
WITH event_data AS (SELECT375 + -- Base gas cost for every log(COALESCE(length(topic0), 0) + COALESCE(length(topic1), 0) + COALESCE(length(topic2), 0) + COALESCE(length(topic3), 0)) / 32 * 375 + -- 375 gas cost for every log topicCOALESCE(length(log.data), 0) * 8 AS gas_cost_per_log, -- 8 gas cost for every byte in log datagas_priceFROM ethereum.logs logJOIN ethereum.transactions tx ON log.tx_hash = tx.hashWHERE log.block_time >= CURRENT_DATE - INTERVAL '30' DAY -- Filter for logs in the last 30 days),gas_cost_data AS (SELECTSUM(gas_cost_per_log * CAST(gas_price AS DOUBLE) / POW(10, 18)) AS total_gas_cost_eth -- Convert gas cost to ETHFROM event_data)SELECT SUM(total_gas_cost_eth) AS total_gas_cost_eth -- Ensure aggregate sum is calculated correctlyFROM gas_cost_data;