i_danWeekly Stats 2 copy
    Updated 2025-02-26
    with new_wallets as (
    SELECT
    MIN(block_timestamp) as create_date
    , origin_from_address
    FROM kaia.defi.ez_dex_swaps
    GROUP BY 2
    ),

    last_week as (
    SELECT
    date_trunc('week', block_timestamp) as week_a
    , SUM(CASE WHEN amount_in_usd IS NULL THEN amount_out_usd ELSE amount_in_usd END) as usd_volume_a
    , COUNT(DISTINCT(tx_hash)) as tx_count_a
    , COUNT(DISTINCT(origin_from_address)) as wallet_count_a
    FROM kaia.defi.ez_dex_swaps
    WHERE block_timestamp < date_trunc('week', current_date)
    GROUP BY 1
    ORDER BY 1 desc
    ),

    previous_week as (
    SELECT
    date_trunc('week', block_timestamp) as week_b
    , SUM(CASE WHEN amount_in_usd IS NULL THEN amount_out_usd ELSE amount_in_usd END) as usd_volume_b
    , COUNT(DISTINCT(tx_hash)) as tx_count_b
    , COUNT(DISTINCT(origin_from_address)) as wallet_count_b
    FROM kaia.defi.ez_dex_swaps
    WHERE block_timestamp < date_trunc('week', current_date)
    GROUP BY 1
    ORDER BY 1 desc
    LIMIT 2
    ),

    table_1 as (
    SELECT *
    FROM last_week
    QueryRunArchived: QueryRun has been archived