Sleepyholders copy
    Updated 2023-06-01
    -- forked from holders @ https://flipsidecrypto.xyz/edit/queries/bacab794-72d3-430d-bcc9-b86b7eb63e1b

    with recieved as(
    select
    to_address,
    sum(amount) received_euroc
    from
    avalanche.core.ez_token_transfers
    where contract_address = '0xc891eb4cbdeff6e073e859e987815ed1505c2acd'
    and to_address not like '0x0000000000000000000000000000000000000000'
    group by to_address
    ),
    sent as(
    select
    from_address,
    sum(amount) sent_euroc
    from
    avalanche.core.ez_token_transfers
    where contract_address = '0xc891eb4cbdeff6e073e859e987815ed1505c2acd'
    and from_address not like '0x0000000000000000000000000000000000000000'
    group by from_address
    )

    select
    count(holder) total_holders,
    round(avg(holding_amount),2) average_holdings,
    median(holding_amount) median_holdings,
    round(count(case when holding_amount > 10 then holding_amount end) / count(holder),2)*100 pct_holders
    from(
    select
    recieved.to_address holder,
    (received_euroc - coalesce(sent_euroc,0)) holding_amount
    from recieved
    left join sent
    on recieved.to_address = sent.from_address
    order by holding_amount desc
    Run a query to Download Data