Query editor
WITH btc_received AS (SELECTaddress,SUM(value) AS valueFROM bitcoin.outputswhere address is not nullGROUP BY 1),btc_sent AS (SELECTaddress, SUM(-value) AS valueFROM bitcoin.inputswhere address is not nullGROUP BY 1),current_balance as (select address, sum(value) as amountfrom (select * from btc_receivedunion allselect * from btc_sent)agroup by 1)selectcasewhen amount <=1 then 'A) <=1 BTC'when amount>1 and amount<=10 then 'B) 1-10 BTC'when amount>10 and amount<=100 then 'C) 10-100 BTC'when amount>100 and amount<=1000 then 'D) 100-1k BTC'when amount>1000 and amount<=10000 then 'E) 1k-10k BTC'when amount>10000 and amount<=100000 then 'F) 10k-100k BTC'when amount>100000 then 'G) 100k+ BTC'end as grp,count(address) as distribution, sum(amount) as total_amount, avg(amount) as averagefrom current_balance-- where amount>0.000001group by 1order by 1 asc