Afonso_DiazRetention Rate
    Updated 2025-05-13
    with

    main as (
    select
    tx_hash,
    block_timestamp,
    sender as user,
    (gas_unit_price * (gas_used / 1e8)) as tx_fee
    from
    aptos.core.fact_transactions
    where
    success
    ),

    monthly_users as (
    select
    date_trunc('month', block_timestamp) as month,
    user,
    min(block_timestamp) over (partition by user) as first_seen
    from main
    ),

    monthly_metrics as (
    select
    month,
    count(distinct user) as active_users,
    count(distinct case when date_trunc('month', first_seen) = month then user end) as new_users,
    count(distinct case when date_trunc('month', first_seen) < month then user end) as returning_users
    from monthly_users
    group by month
    ),

    retention as (
    select
    w1.month as current_month,
    w2.month as previous_month,
    QueryRunArchived: QueryRun has been archived