datavortexsuccessive-rose
    Updated 2024-11-23
    WITH TotalFees AS (
    SELECT
    SUM(tx_fee) AS total_fees_in_bsc,
    COUNT(DISTINCT tx_hash) AS total_transactions
    FROM bsc.core.fact_transactions
    WHERE status = 'SUCCESS'
    AND DATE_TRUNC('month', block_timestamp) = DATE_TRUNC('month', CURRENT_DATE)
    ),
    BSCPrice AS (
    SELECT
    AVG(price) AS bsc_price
    FROM bsc.price.ez_prices_hourly
    WHERE symbol = 'BNB'
    AND DATE_TRUNC('month', hour) = DATE_TRUNC('month', CURRENT_DATE)
    )
    SELECT
    tf.total_transactions,
    tf.total_fees_in_bsc,
    tf.total_fees_in_bsc * bp.bsc_price AS total_fees_in_usd,
    tf.total_fees_in_bsc / tf.total_transactions AS avg_fee_per_transaction_in_bsc,
    ROUND((tf.total_fees_in_bsc / tf.total_transactions) * bp.bsc_price, 4) AS avg_fee_per_transaction_in_usd
    FROM
    TotalFees tf,
    BSCPrice bp;

    QueryRunArchived: QueryRun has been archived