Query editor
WITHgas_usage AS (SELECTDATE_TRUNC('day', block_time) AS txn_day,t.gas_used,priority_fee_per_gas,t.gas_price,-- t.l1_fee as security,b.base_fee_per_gas/1e9 * t.gas_used as "base fee",-- ((gas_price - priority_fee_per_gas)/1e9) * (t.gas_used) as "base fee",(priority_fee_per_gas/1e9)*(t.gas_used) as "priority fee",(gas_price / 1e9)*(t.gas_used) AS total_gas_cost_ETHFROMbase.transactions as tJOINbase.blocks as bOn t.block_number = b.number),daily_eth_price AS (SELECTDATE_TRUNC('day', minute) AS price_day,AVG(price) AS avg_price_usd /* Averaging in case there are multiple entries per day */FROMprices.usdWHEREblockchain = 'ethereum'AND contract_address = 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 --USE WETH price to reflect ETH priceGROUP BYDATE_TRUNC('day', minute))SELECTg.txn_day,--p.avg_price_usd,--SUM(g.gas_used) AS total_gas_used,SUM(g."base fee")/1e9 AS "Daily Total Base fee",SUM(g."priority fee")/1e9 AS "Daily Total Priority fee",-- SUM(g."base fee" + g."priority fee")/1e9 AS "total fee",--SUM(g.security/1e18) as security,--AVG(g.gas_price) AS average_gas_price,SUM(g.total_gas_cost_ETH)/1e9 AS total_spent_on_gas_ETH--SUM(g."true base fee")/1e9 as ZERO,--(SUM(g.total_gas_cost_ETH)) * p.avg_price_usd AS total_spent_on_gas_usdFROMgas_usage AS gJOIN daily_eth_price AS p ON g.txn_day = p.price_dayWHEREg.txn_day > TRY_CAST('2023-01-01' AS TIMESTAMP)GROUP BYg.txn_day,p.avg_price_usdORDER BYg.txn_day DESC