Last active
June 10, 2019 08:18
-
-
Save medvedev1088/d4231cef434ef36ed4177bec11491ed8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#standardSQL | |
-- MIT License | |
-- Copyright (c) 2018 Evgeny Medvedev, [email protected] | |
with double_entry_book as ( | |
-- debits | |
select array_to_string(array(select * from unnest(outputs.addresses) order by 1), ',') as address, | |
outputs.value as value | |
from bitcoin_blockchain.transactions as transactions, | |
unnest(transactions.outputs) as outputs | |
union all | |
-- credits | |
select array_to_string(array(select * from unnest(inputs.addresses) order by 1), ',') as address, | |
-inputs.value as value | |
from bitcoin_blockchain.transactions as transactions, | |
unnest(transactions.inputs) as inputs | |
) | |
select address, sum(value) as balance | |
from double_entry_book | |
group by address | |
order by balance desc | |
limit 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment