nitsUSDC asset dsitribution
    Updated 2022-02-11
    with sender as (SELECT asset_sender as addr, sum(asset_amount)*(-1) as total_amt from algorand.asset_transfer_transaction
    where asset_id = '31566704' and asset_amount is not NULL
    GROUP by 1),
    receiver as (SELECT asset_receiver as addr, sum(asset_amount)*(1) as total_amt from algorand.asset_transfer_transaction
    where asset_id = '31566704' and asset_amount is not NULL
    GROUP by 1)

    SELECT distribution, count(*) as users_in_this_range from
    (SELECT *, case when net_balance < 100 then 'a-less than 100'
    when net_balance >= pow(10,2) and net_balance < pow(10,3) then 'b-100-1k'
    when net_balance >= pow(10,3) and net_balance < pow(10,4) then 'c-1k-10k'
    when net_balance >= pow(10,4) and net_balance < pow(10,5) then 'd-10k-100k'
    when net_balance >= pow(10,5) and net_balance < pow(10,6) then 'e-100k-1M'
    when net_balance >= pow(10,6) then 'f-1M+'
    end as distribution
    from
    (SELECT addr, sum(total_amt)/pow(10,6) as net_balance from
    (SELECT * from sender
    UNION ALL
    SELECT * from receiver )
    GROUP by 1))
    where distribution is not NULL
    GROUP by 1
    order by 1
    LIMIT 1000
    Run a query to Download Data