algoinsightsSUSHISWAP (POLYGON ) MONTHLY USER ONBOARDING
    Updated 2024-08-29
    -- forked from freeman_7 / UNISWAP (Ethereum chain ) MONTHLY USER ONBOADING AND VS RETENTION @ https://flipsidecrypto.xyz/freeman_7/q/4rR9JLYamNbd/uniswap-ethereum-chain-monthly-user-onboading-and-vs-retention

    With first_interaction as (
    select origin_from_address as user,
    Min(date_trunc('month',block_timestamp)) as first_month_interaction
    From polygon.defi.ez_dex_swaps
    Where platform like 'sushiswap%'
    --And block_timestamp::date > ' 2023-12-31'
    Group by user ),

    Monthly_users as (
    Select origin_from_address as user,
    Date_trunc('month', block_timestamp) as monthly_interaction
    From polygon.defi.ez_dex_swaps
    Where platform like 'sushiswap%'
    And block_timestamp::date > '2023-12-31'
    ),

    User_classification as (
    Select mi.user as user,
    Mi.monthly_interaction as month,
    Case
    When Mi.monthly_interaction = fi.first_month_interaction then 'new_user'
    Else 'regular_user'
    End as user_type
    From Monthly_users mi
    Join first_interaction fi ON fi.user = mi.user
    )

    Select month,
    count(distinct user) as total_monthly_user,
    Count(distinct case when user_type = 'regular_user' then user end) as old_users,
    Count(distinct case when user_type = 'new_user' then user end) as new_users
    From User_classification
    Group by month
    Order by month
    QueryRunArchived: QueryRun has been archived