Created
January 23, 2019 14:59
-
-
Save allenday/de58b4fbecdb21a3a9f17855ff588d47 to your computer and use it in GitHub Desktop.
Query Dogecoin balance by timestamp in BigQuery
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
| WITH double_entry_book AS ( | |
| -- debits | |
| SELECT | |
| array_to_string(inputs.addresses, ",") as address | |
| , inputs.type | |
| , -inputs.value as value | |
| FROM `crypto-etl-bitcoin-prod.dogecoin_blockchain.inputs` as inputs | |
| UNION ALL | |
| -- credits | |
| SELECT | |
| array_to_string(outputs.addresses, ",") as address | |
| , outputs.type | |
| , outputs.value as value | |
| FROM `crypto-etl-bitcoin-prod.dogecoin_blockchain.outputs` as outputs | |
| ) | |
| SELECT | |
| address | |
| , type | |
| , sum(value) as balance | |
| FROM double_entry_book | |
| GROUP BY 1,2 | |
| ORDER BY balance DESC | |
| LIMIT 1000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment