j-hackworthPolygon_stats
    Updated 2022-07-14
    with MATIC as (SELECT
    DATE(block_timestamp) as "Date",
    COUNT(tx_hash) as "# of Transactions - Matic",
    percentile_cont(.1) within GROUP (ORDER BY tx_fee) as ".1 Percentile of TX Fees",
    percentile_cont(.9) within GROUP (ORDER BY tx_fee) as ".9 Percentile of TX Fees",
    AVG(tx_fee) as "AVG Transaction Fee",
    AVG("Price") as "AVG Matic Price",
    AVG(tx_fee * "Price") as "AVG Transaction Fee ($USD)",
    SUM(tx_fee) as "Total Fees Per Day",
    SUM(tx_fee * "Price") as "Total Fees Per Day ($USD)",
    SUM(SUM(tx_fee)) OVER (ORDER BY DATE(block_timestamp)) as "Cumulative Transaction Fees",
    SUM(COUNT(tx_fee)) OVER (ORDER BY DATE(block_timestamp)) as "Cumulative Transactions - Matic",
    SUM(SUM(tx_fee * "Price")) OVER (ORDER BY DATE(block_timestamp)) as "Cumulative Transaction Fees ($USD)"
    FROM polygon.core.fact_transactions t
    LEFT JOIN (SELECT DATE(hour) as "D",
    AVG(price) as "Price" FROM ethereum.core.fact_hourly_token_prices WHERE symbol = 'MATIC' GROUP BY DATE(hour)) a ON a."D" = DATE(block_timestamp)
    WHERE DATE(block_timestamp) >= '2022-01-01'
    GROUP BY DATE(block_timestamp)
    ORDER BY DATE(block_timestamp) DESC),


    active as (SELECT
    "Date",
    COUNT(DISTINCT("Address")) as "# of Active Users",
    AVG(COUNT(DISTINCT("Address"))) OVER (ORDER BY "Date") as "Running Average Active Users"
    FROM (
    SELECT
    DATE(block_timestamp) as "Date",
    from_address as "Address"
    FROM polygon.core.fact_transactions t
    WHERE DATE(block_timestamp) >= '2022-01-01'

    UNION ALL

    SELECT
    DATE(block_Timestamp) as "Date",
    Run a query to Download Data