Analyze Bitcoin data with Google BigQuery

Ryan Lindbeck
2 min readNov 29, 2020

Google BigQuery now has public Bitcoin datasets that allow users to analyze historical transaction data using standard SQL. Below are a few example SQL statements for analyzing the following metrics:

  • Total number of blocks.
  • Number of transactions in the last 24 hours.
  • Average number of transactions per hour this year (2020).
  • Bitcoins sent in the last 24 hours.
  • Average transaction value this year (2020).
  • Average transaction value this year (2020).

Visit here for more information on how to add public data sets to your BigQuery instance.

Total number of blocks

select count("hash") 
from bigquery-public-data.crypto_bitcoin.blocks
;

Number of transactions in the last 24 hours

select count("hash")
from bigquery-public-data.crypto_bitcoin.transactions as trans
where cast(trans.block_timestamp as Date) >= DATE_SUB(CURRENT_DATE(), INTERVAL 1 DAY);

Average number of transactions per hour this year (2020)

select count("hash") / 8760 as averageNumTrans
from bigquery-public-data.crypto_bitcoin.transactions as trans
where trans.block_timestamp_month between '2020-01-01' and '2020-12-31';

Bitcoins sent in the last 24 hours

select SUM(output_value) * 0.00000001 as bitcoinsSent
from bigquery-public-data.crypto_bitcoin.transactions as transwhere
cast(trans.block_timestamp as Date) >= DATE_SUB(CURRENT_DATE(), INTERVAL 1 DAY);

Average transaction value this year (2020)

select 
(sum(output_value) / count("hash") * 0.00000001) as averageTransactionFee
from bigquery-public-data.crypto_bitcoin.transactions as transwhere
trans.block_timestamp_month between '2020-01-01' and '2020-12-31';

Average transaction fee this year (2020)

select 
(sum(fee) / count("hash") * 0.00000001) as averageTransactionValue
from bigquery-public-data.crypto_bitcoin.transactions as trans
where trans.block_timestamp_month between '2020-01-01' and '2020-12-31';

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Ryan Lindbeck
Ryan Lindbeck

Written by Ryan Lindbeck

Strategic Visionary Leader in Healthcare Analytics | Software & Data Engineer

No responses yet

Write a response