Updated 2024-01-04
    with tb1 as (SELECT
    To_ADDRESS,
    sum(RAW_AMOUNT/1e18) as volume_receive
    from avalanche.core.fact_token_transfers
    where CONTRACT_ADDRESS = lower ('0x0EF27Ddc8F89D4886E89d630De089962FfC12E43')
    group by 1),

    tb2 as (SELECT
    From_ADDRESS,
    sum(RAW_AMOUNT/1e18) as volume_sent
    from avalanche.core.fact_token_transfers
    where CONTRACT_ADDRESS = lower ('0x0EF27Ddc8F89D4886E89d630De089962FfC12E43')
    group by 1),

    tb3 as (select
    tb1.to_address as user,
    ifnull(volume_receive,0) - ifnull(volume_sent,0) as volume_hold
    from tb1
    left outer join tb2 on tb1.to_address=tb2.From_ADDRESS
    )


    select
    count(distinct user) as holders,
    median(volume_hold) as median_volume,
    avg(volume_hold) as average_volume
    from tb3
    where volume_hold>0


    QueryRunArchived: QueryRun has been archived