MLDZMNWGF4
    Updated 2022-11-28
    with tb1 as (select
    distinct recipient as user1,
    sum(amount) as total_recieved
    from flow.core.ez_token_transfers
    where token_contract = 'A.1654653399040a61.FlowToken'
    and tx_succeeded = 'TRUE'
    group by 1),

    tb2 as (select
    distinct sender as user2,
    sum(amount) as total_sent
    from flow.core.ez_token_transfers s left join tb1 b on s.sender=b.user1
    where token_contract = 'A.1654653399040a61.FlowToken'
    and tx_succeeded = 'TRUE'
    and sender in (select user1 from tb1)
    group by 1),

    tb3 as (select
    distinct user1 as users,
    total_recieved - total_sent as net_flow
    from tb1 s left join tb2 b on s.user1 = b.user2
    left join flow.core.dim_contract_labels c on s.user1 = c.account_address
    where total_recieved>total_sent
    and CONTRACT_NAME is null
    )

    select
    CASE
    WHEN net_flow < 1 then 'a. Below 1'
    WHEN net_flow < 100 then 'b. 1 - 100'
    WHEN net_flow < 1000 then 'c. 100 - 1,000'
    WHEN net_flow < 10000 then 'd. 1,000 - 10,000'
    WHEN net_flow >= 10000 then 'e. Above 10,000'
    end as gp,
    count(distinct users) as no_users
    from tb3
    Run a query to Download Data