AephiaPOLIS Holders
    Updated 2023-03-27
    -- forked from be45319e-d904-41a3-aeee-6176a0dc2d4a

    with tab4 as (
    with tab3 as (
    with tab1 as (select tx_from as sender, sum(amount) as volume_out
    from solana.core.fact_transfers
    where mint in ('poLisWXnNRwC6oBu1vHiuKQzFjGL4XDSu4g9qjz9qVk')
    group by 1),

    tab2 as (select tx_to as receiver, sum(amount) as volume_in
    from solana.core.fact_transfers
    where mint in ('poLisWXnNRwC6oBu1vHiuKQzFjGL4XDSu4g9qjz9qVk')
    group by 1)

    select sender as "Holder", volume_in, volume_out, case
    when volume_in is null then 0
    else volume_in
    end as vol_in, case
    when volume_out is null then 0
    else volume_out
    end as vol_out
    from tab1 left join tab2 on tab1.sender=tab2.receiver
    order by 2 desc)

    select "Holder", vol_in-vol_out as "Balance", case
    when vol_in-vol_out<=1 and vol_in-vol_out>0 then 'Balance<=1'
    when vol_in-vol_out>1 and vol_in-vol_out<=10 then '1<Balance<=10'
    when vol_in-vol_out>10 and vol_in-vol_out<=100 then '10<Balance<=100'
    when vol_in-vol_out>100 and vol_in-vol_out<=1000 then '100<Balance<=1k'
    when vol_in-vol_out>1000 and vol_in-vol_out<=10000 then '1k<Balance<=10k'
    when vol_in-vol_out>10000 and vol_in-vol_out<=100000 then '10k<Balance<=100k'
    when vol_in-vol_out>100000 and vol_in-vol_out<=1000000 then '100k<Balance<=1M'
    when vol_in-vol_out>1000000 then 'Balance>1M'
    end as "Class"
    from tab3
    where vol_in-vol_out>0)
    Run a query to Download Data