tannylimited-cyan
    Updated 2024-11-07
    -- Step 1: Identify unique users and their first interaction month
    WITH initial_users AS (
    SELECT DISTINCT sender AS user_address,
    DATE_TRUNC('month', block_timestamp) AS first_month
    FROM ethereum.uniswapv3.ez_swaps -- Adjust to the correct table name if different
    ),

    -- Step 2: Track user interactions for each month
    monthly_interactions AS (
    SELECT sender AS user_address,
    DATE_TRUNC('month', block_timestamp) AS month
    FROM ethereum.uniswapv3.ez_swaps
    )

    -- Step 3: Calculate monthly retention
    SELECT iu.first_month,
    mi.month,
    COUNT(DISTINCT mi.user_address) AS returning_users
    FROM initial_users iu
    JOIN monthly_interactions mi
    ON iu.user_address = mi.user_address
    AND mi.month >= iu.first_month -- Ensure we’re only tracking users from their first month onward
    GROUP BY iu.first_month, mi.month
    ORDER BY iu.first_month, mi.month;

    QueryRunArchived: QueryRun has been archived