Hosseinwallets holders by size
    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
    ),
    list3 as (
    select wallet_address, (list1.amount_sum - list2.amount_sum) as total_balance
    from list1
    join list2 using (wallet_address)
    )

    select (case
    when total_balance between 1 and 100 then '1 - 100'
    when total_balance between 100 and 1000 then '100 - 1000'
    when total_balance between 1000 and 10000 then '1000 - 10000'
    when total_balance between 10000 and 100000 then '10000 - 100000'
    when total_balance between 100000 and 1000000 then '100000 - 1000000'
    else '> 1000000' end
    ) as type, count(distinct(wallet_address)) as wallets_count
    from list3
    group by type
    order by wallets_count desc
    Run a query to Download Data