Query editor
WITH daily_fees AS (SELECTgf.block_date,date_trunc('week', gf.block_date) AS week_start_date,-- Daily Fee Totals (Native Currency)SUM(gf.tx_fee) AS daily_fee_native,-- Daily Fee Totals (USD)SUM(gf.tx_fee_usd) AS daily_fee_usd, -- Added comma hereAVG(gf.tx_fee_usd) AS daily_avg_tx_fee -- Renamed for clarityFROMgas.fees gf-- Filter out nulls/zeroes and specify blockchainWHEREgf.tx_fee IS NOT NULLAND gf.tx_fee > 0AND gf.tx_fee_usd IS NOT NULLAND blockchain = 'plasma' -- Explicit blockchain filterGROUP BY1, 2)SELECTdf.block_date,df.week_start_date,-- 1. Daily Feesdf.daily_fee_native,df.daily_fee_usd,df.daily_avg_tx_fee, -- Included the new metric-- 2. Weekly Fees (Sum of daily fees within the week)SUM(df.daily_fee_native) OVER (PARTITION BY df.week_start_date) AS weekly_fee_native,SUM(df.daily_fee_usd) OVER (PARTITION BY df.week_start_date) AS weekly_fee_usd,-- Additional Weekly Metrics: Average Tx Fee (Average of Daily Averages)AVG(df.daily_avg_tx_fee) OVER (PARTITION BY df.week_start_date) AS weekly_avg_tx_fee,-- 3. Lifetime Fees (Total Aggregate)SUM(df.daily_fee_native) OVER () AS lifetime_fee_native,SUM(df.daily_fee_usd) OVER () AS lifetime_fee_usd,-- BONUS METRIC: Running Cumulative Fee Total (TVF/Total Value of Fees)SUM(df.daily_fee_usd) OVER (ORDER BY df.block_date) AS cumulative_fee_usd_to_dateFROMdaily_fees dfORDER BYdf.block_date DESC