elsina2024-08-21: NEAR Staker Wallet Age Distribution
    Updated 2024-10-19
    with t1 as (
    SELECT
    signer_id as user,
    min(block_timestamp) as min_stake_tx
    from
    near.gov.fact_staking_actions
    where
    action in ('staking', 'unstaking')
    group by
    user
    ),

    t2 as (
    SELECT
    user,
    min_stake_tx,
    min(block_timestamp) as min_tx
    from
    near.core.fact_transactions b left join t1 a on user = tx_signer
    group by
    user, min_stake_tx
    ),

    t3 as (
    select
    user,
    datediff('day' , min_tx , min_stake_tx) as age_wallets
    from t2
    )

    select
    case
    when age_wallets < 1 then 'A : < 1 day'
    when age_wallets between 1 and 30 then 'B : < 1 month'
    when age_wallets between 31 and 90 then 'C : < 3 months'
    when age_wallets between 91 and 180 then 'D : < 6 months'
    QueryRunArchived: QueryRun has been archived