Afonso_Diazgas fee trends
    Updated 2025-02-24
    WITH main AS (
    SELECT
    tx_hash,
    block_timestamp,
    tx_fee
    FROM kaia.core.fact_transactions
    ),
    daily_fees AS (
    SELECT
    DATE_TRUNC('month', block_timestamp) AS tx_day,
    COUNT(tx_hash) AS total_tx,
    SUM(tx_fee) AS total_fees,
    AVG(tx_fee) AS avg_fee_per_tx
    FROM main
    GROUP BY tx_day
    ),
    fee_trends AS (
    SELECT
    tx_day,
    total_tx,
    total_fees,
    avg_fee_per_tx,
    LAG(avg_fee_per_tx) OVER (ORDER BY tx_day) AS prev_avg_fee,
    (avg_fee_per_tx - LAG(avg_fee_per_tx) OVER (ORDER BY tx_day)) / NULLIF(LAG(avg_fee_per_tx) OVER (ORDER BY tx_day), 0) * 100 AS fee_change_pct
    FROM daily_fees
    )
    SELECT
    tx_day,
    total_tx,
    total_fees,
    avg_fee_per_tx,
    fee_change_pct
    FROM fee_trends
    ORDER BY tx_day
    QueryRunArchived: QueryRun has been archived