carlesmontalaCopy of 2- Who's Got The Flow?
    Updated 2022-11-28
    with depositt as (
    select event_data:to as flowuser,
    sum (event_data:amount) as Deposit_Volume
    from flow.core.fact_events
    where event_contract = 'A.1654653399040a61.FlowToken'
    and event_type = 'TokensDeposited'
    and tx_succeeded = 'TRUE'
    group by 1),

    withdrawt as (
    select event_data:from as flowuser,
    sum (event_data:amount) as Withdraw_Volume
    from flow.core.fact_events
    where event_contract = 'A.1654653399040a61.FlowToken'
    and event_type = 'TokensWithdrawn'
    and tx_succeeded = 'TRUE'
    group by 1),

    maintable as (
    select t1.flowuser,
    sum (deposit_volume - withdraw_volume) as Balance
    from depositt t1 join withdrawt t2 on t1.flowuser = t2.flowuser
    where t1.flowuser != 'null'
    group by 1)

    select case when balance < 10 then 'Holding Less Than 10 $FLOW'
    when balance >= 10 and balance < 100 then 'Holding 10 - 100 $FLOW'
    when balance >= 100 and balance < 1000 then 'Holding 100 - 1000 $FLOW'
    when balance >= 1000 and balance < 10000 then 'Holding 1000 - 10000 $FLOW'
    else 'Holding More Than 10000 $FLOW' end as type,
    count (distinct flowuser) as Holders_Count
    from maintable
    group by 1
    order by 2 desc
    Run a query to Download Data