Pmisha-bmlMdxbento2.polygon
    Updated 2022-05-18
    with total as (with t1 as(select
    FROM_ADDRESS as u1,
    min(BLOCK_TIMESTAMP) as add_time
    from polygon.udm_events
    where TO_ADDRESS= '0x0319000133d3ada02600f0875d2cf03d442c3367'
    and BLOCK_TIMESTAMP>= '2022-01-01'
    group by 1),

    t2 as(select
    TO_ADDRESS as u2,
    max(BLOCK_TIMESTAMP) as remove_time

    from polygon.udm_events
    where FROM_ADDRESS= '0x0319000133d3ada02600f0875d2cf03d442c3367'
    and BLOCK_TIMESTAMP>= '2022-01-01'
    group by 1)

    SELECT
    t1.u1 as users,
    abs(DATEDIFF(day, add_time,remove_time)) as average_time
    from t1 inner join t2 on t1.u1=t2.u2)

    select
    case
    when average_time<=10 then 'under 10 days'
    when average_time between 11 and 50 then '11-50 days'
    when average_time between 51 and 100 then '51-100 days'
    when average_time>=100 then 'over 100 days'
    end as times,
    count (distinct users) as wallets
    from total group by 1 having times is not null

    Run a query to Download Data