i_dan2024-05-28 12:31 PM
    Updated 2024-05-28
    WITH recent_transactions AS (
    SELECT
    origin_from_address,
    amount_in_usd,
    amount_out_usd,
    MIN(date_trunc('day', block_timestamp)) AS first_date
    FROM
    base.defi.ez_dex_swaps
    WHERE block_timestamp >= (current_date - INTERVAL '7 DAYS')
    GROUP BY 1, 2, 3
    ),
    filtered_addresses AS (
    SELECT
    origin_from_address
    FROM
    base.defi.ez_dex_swaps
    WHERE block_timestamp < (current_date - INTERVAL '7 DAYS')
    GROUP BY origin_from_address
    )

    SELECT
    COUNT(DISTINCT r.origin_from_address) AS new_users
    , r.first_date AS date
    , SUM(ABS(amount_in_usd) + ABS(amount_out_usd)) / 2 AS New_users_transaction_volume
    FROM
    recent_transactions r
    LEFT JOIN filtered_addresses f
    ON r.origin_from_address = f.origin_from_address
    WHERE
    f.origin_from_address IS NULL
    GROUP BY 2
    ORDER BY r.first_date;


    --SELECT
    -- COUNT(DISTINCT origin_from_address) AS users
    QueryRunArchived: QueryRun has been archived