pimi1356-HdnUm3 USDH Distribution
    Updated 2022-10-09
    --credit to @HaiRong21
    with outflow as (
    select TX_FROM as sellers, sum(AMOUNT) as outt
    from solana.core.fact_transfers
    where MINT='USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX'
    group by 1
    ),
    inflow as (
    select TX_TO as buyers, sum(AMOUNT) as intt
    from solana.core.fact_transfers
    where MINT='USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX'
    group by 1
    ),
    holder as (
    select (b.intt-a.outt) as balance, a.sellers as wallet
    from outflow a join inflow b on a.sellers=b.buyers
    order by 1 DESC
    )
    SELECT 'Whale' as Class, count (case WHEN balance >=100000 then wallet END) as "Number of Addresses"
    from holder
    UNION
    SELECT 'Octopus', count (case WHEN balance between 10000 and 100000 then wallet END)
    from holder
    UNION
    SELECT 'Dolphin', count (case WHEN balance between 1000 and 10000 then wallet END)
    from holder
    UNION
    SELECT 'shrimp', count (case WHEN balance between 100 and 1000 then wallet END)
    from holder
    UNION
    SELECT 'fish', count (case WHEN balance between 10 and 100 then wallet END)
    from holder
    UNION
    SELECT 'newcomer', count (case WHEN balance <=10 then wallet END)
    from holder
    Run a query to Download Data