Skip to content

Instantly share code, notes, and snippets.

@rifkiamil
rifkiamil / football-withjoins.DBML
Last active October 27, 2021 22:43
Football Data Database Markup Language - with joins
Project project_name {
database_type: 'BigQuery'
Note: 'Football Data by https://github.com/dcaribou'
}
Table appearances {
player_id INTEGER
game_id INTEGER
appearance_id STRING [pk]
league_id STRING
@rifkiamil
rifkiamil / football-nojoins.DBML
Last active October 27, 2021 22:05
Football Data Database Markup Language - no joins
Project project_name {
database_type: 'BigQuery'
Note: 'Football data'
}
Table appearances {
player_id INTEGER
game_id INTEGER
appearance_id STRING [pk]
league_id STRING
@rifkiamil
rifkiamil / sql-eth-03.sql
Created February 23, 2021 07:11
Find Ethereum - Internal transactions - Matchs Advanced view on Etherscan.io
## Find Ethereum - Internal transactions - Matchs Advanced view on Etherscan.io
SELECT *
FROM `bigquery-public-data.crypto_ethereum.traces`
WHERE DATE(block_timestamp) = "2021-02-12"
and trace_address IS NOT NULL
and block_number = 11838934
ORDER BY transaction_index
@rifkiamil
rifkiamil / sql-eth-02.sql
Created February 23, 2021 06:54
Find Ethereum - Internal transactions with values - Matchs default view on Etherscan.io
## Find Ethereum - Internal transactions with values - Matchs default view on Etherscan.io
SELECT *
FROM `bigquery-public-data.crypto_ethereum.traces`
WHERE DATE(block_timestamp) = "2021-02-12"
and trace_address IS NOT NULL
and block_number = 11838934
and value > 0
ORDER BY transaction_index
@rifkiamil
rifkiamil / sql-eth-01.sql
Created February 19, 2021 12:36
Top 20 balances on Ethereum with correct decimal place
## Below is the query that will give you top 20 balances on Ethereum
SELECT Address as EthAddress,
CAST(eth_balance as NUMERIC)/1000000000000000000 as EthBalance
FROM `bigquery-public-data.crypto_ethereum.balances`
ORDER BY Eth_balance DESC
LIMIT 20
//// Advanced relational diagram for bigquery-public-data:crypto_bitcoin
//// Update on 2021-02-12
//// diagram by @rifkiamil
//// For the https://github.com/blockchain-etl/bitcoin-etl project
Project "bigquery-public-data:Crypto_Bitcoin" {
database_type: 'BigQuery'
Note: 'Advanced Bitcoin diagram layout (not using RECORD field type)'
}
@rifkiamil
rifkiamil / sql-bitcoin-05.sql
Created February 17, 2021 00:37
SQL Bitcoin Part 2 - WHERE block_timestamp_month = Dec 2013 and Bitcoin Value more then 1 Bitcoin and hash transcation is e7f...fd7
SELECT block_timestamp,
block_timestamp_month,
output_value
FROM `bigquery-public-data.crypto_bitcoin.transactions`
WHERE block_timestamp_month = '2013-12-01'
and output_value > 10000000
and `hash` = 'e7f8fe18fdc039535fef6d3e82fc086cca2e50d2e1f7f68ab1e97ee8dcafdfd7'
@rifkiamil
rifkiamil / sql-bitcoin-04.sql
Created February 15, 2021 16:27
SQL Bitcoin Part 2 - Find transactions with block_timestamp, block_timestamp_month, output_value WHERE block_timestamp_month
SELECT block_timestamp, block_timestamp_month, output_value
FROM `bigquery-public-data.crypto_bitcoin.transactions`
WHERE block_timestamp_month = '2013-12-01'
@rifkiamil
rifkiamil / sql-bitcoin-03.sql
Created February 15, 2021 16:24
SQL Bitcoin Part 2 - Find transactions with block_timestamp, block_timestamp_month, output_value
SELECT block_timestamp, block_timestamp_month, output_value
FROM `bigquery-public-data.crypto_bitcoin.transactions`
@rifkiamil
rifkiamil / Full relational diagram - sql with partitioned field.sql
Created February 12, 2021 17:09
Full relational diagram - sql with partitioned field
SELECT
transactions.hash as transaction_hash,
transactions.block_hash,
transactions.block_number,
transactions.block_timestamp,
outputs.index,
outputs.script_asm,
outputs.script_hex,
outputs.required_signatures,
outputs.type,