i_danAvax VS Base: New/Old Traders
    Updated 2024-11-27
    WITH all_base AS (
    SELECT
    origin_from_address AS Trader
    , SUM(CASE WHEN amount_in_usd IS NOT NULL AND amount_out_usd IS NOT NULL THEN ((amount_in_usd+amount_out_usd)/2)
    WHEN amount_in_usd IS NULL AND amount_out_usd IS NULL THEN NULL
    WHEN amount_in_usd IS NULL AND amount_out_usd IS NOT NULL THEN amount_out_usd
    WHEN amount_in_usd IS NOT NULL AND amount_out_usd IS NULL THEN amount_in_usd
    ELSE NULL END) AS Volume
    , COUNT(DISTINCT tx_hash) AS Transactions
    FROM base.defi.ez_dex_swaps
    WHERE year(block_timestamp) = 2024
    AND (amount_in_usd IS NOT NULL OR amount_out_usd IS NOT NULL)
    GROUP BY 1
    ),

    new_base AS (
    SELECT
    origin_from_address AS trader
    FROM base.defi.ez_dex_swaps
    GROUP BY 1
    HAVING year(min(block_timestamp)) = '2024'
    ),

    all_avax AS (
    SELECT
    origin_from_address AS Trader
    , SUM(CASE WHEN amount_in_usd IS NOT NULL AND amount_out_usd IS NOT NULL THEN ((amount_in_usd+amount_out_usd)/2)
    WHEN amount_in_usd IS NULL AND amount_out_usd IS NULL THEN NULL
    WHEN amount_in_usd IS NULL AND amount_out_usd IS NOT NULL THEN amount_out_usd
    WHEN amount_in_usd IS NOT NULL AND amount_out_usd IS NULL THEN amount_in_usd
    ELSE NULL END) AS Volume
    , COUNT(DISTINCT tx_hash) AS Transactions
    FROM avalanche.defi.ez_dex_swaps
    WHERE year(block_timestamp) = 2024
    AND (amount_in_usd IS NOT NULL OR amount_out_usd IS NOT NULL)
    GROUP BY 1
    QueryRunArchived: QueryRun has been archived