HosseinNEAR Distribution
    Updated 2022-09-08
    with
    list1 as (
    select tx_receiver as wallet_address, sum(tx:actions[0]:transfer:deposit / pow(10, 24)) as amount_sum
    from near.core.fact_transactions
    where tx_status = 'Success'
    and tx:actions[0]:transfer:deposit > 0
    group by tx_receiver
    ),
    list2 as (
    select tx_signer as wallet_address, sum(tx:actions[0]:transfer:deposit / pow(10, 24)) as amount_sum
    from near.core.fact_transactions
    where tx_status = 'Success'
    and tx:actions[0]:transfer:deposit > 0
    group by tx_signer
    ),
    near_balance as (
    select list1.wallet_address, (list1.amount_sum - list2.amount_sum) as total_balance
    from list1
    join list2 on list1.wallet_address = list2.wallet_address
    )
    select count(case when total_balance between 1 and 100 then wallet_address end) as dist, '1 - 100' as dist_name
    from near_balance
    union all
    select count(case when total_balance between 100 and 1000 then wallet_address end), '100 - 1000'
    FROM near_balance
    union all
    select count(case when total_balance between 1000 and 10000 then wallet_address end), '1000 - 10000'
    FROM near_balance
    union all
    select count(case when total_balance between 10000 and 100000 then wallet_address end), '10000 - 100000'
    FROM near_balance
    union all
    select count(case when total_balance between 100000 and 1000000 then wallet_address end), '100000 - 1000000'
    from near_balance
    Run a query to Download Data