Query editor
with main as (SELECTfe.block_time,fe.block_number,fe.gas_used * (CAST(fe.gas_price AS DECIMAL(38,0)) / 1e18 * pb.price) AS total_gas_usedFROM gas.fees feLEFT JOIN prices.hour pbON DATE_TRUNC('hour', fe.block_time) = pb.timestampAND fe.tx_fee_currency = pb.contract_addressAND pb.blockchain = 'ethereum'WHERE fe.blockchain = 'ethereum'AND fe.block_time >= NOW() - INTERVAL '2' DAY),per_block as (SELECTblock_number,SUM(total_gas_used) as gas_per_blockFROM mainGROUP BY 1)SELECTblock_number,gas_per_block,gas_per_block - LAG(gas_per_block) OVER (ORDER BY block_number ASC) AS deltaFROM per_blockORDER BY block_number DESC-- Window functions combined with math functions to perform calculations over set of rows-- Do conversions early on so you can do calculations later and avoid aggregate errors