Skip to content

Instantly share code, notes, and snippets.

@orcaman
Created January 1, 2019 07:13
Show Gist options
  • Save orcaman/dd05ddce5634ba4b0ba4781e51c64126 to your computer and use it in GitHub Desktop.
Save orcaman/dd05ddce5634ba4b0ba4781e51c64126 to your computer and use it in GitHub Desktop.
How Many Bitcoins Were Sent Per Month Per Year
#standardSQL
SELECT
EXTRACT(year
FROM
o.day) AS year,
EXTRACT(month
FROM
o.day) AS month,
SUM(o.output_satoshis) * 0.00000001 AS btc
FROM (
SELECT
TIMESTAMP_MILLIS((timestamp - MOD(timestamp,86400000))) AS day,
output.output_pubkey_base58 AS output_key,
output.output_satoshis
FROM
`bigquery-public-data.bitcoin_blockchain.transactions`,
UNNEST(outputs) AS output
GROUP BY
day,
output_key,
output_satoshis ) AS o
GROUP BY
1,
2
ORDER BY
1,
2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment