Created
April 8, 2019 07:09
-
-
Save aknirmal90/fdd6c9d2f4f8c2e6a52d4beaf75c8e67 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
WITH shared_inputs AS ( | |
SELECT | |
ARRAY_TO_STRING(inputs.addresses, '') AS address | |
FROM `bigquery-public-data.crypto_bitcoin.transactions` AS txns | |
, UNNEST(txns.inputs) AS inputs | |
WHERE txns.hash IN | |
( | |
SELECT | |
txns.hash as tx_hash | |
FROM `bigquery-public-data.crypto_bitcoin.transactions` AS txns | |
CROSS JOIN UNNEST(txns.inputs) AS inputs | |
WHERE | |
ARRAY_TO_STRING(inputs.addresses, '') IN (SELECT address FROM `bitcoin-etl.clusttering.iteration_3`) | |
) | |
GROUP BY 1 | |
), | |
miso AS ( | |
SELECT | |
ARRAY_TO_STRING(outputs.addresses, '') AS address | |
FROM `bigquery-public-data.crypto_bitcoin.transactions` AS txns | |
CROSS JOIN UNNEST(txns.outputs) AS outputs | |
WHERE txns.hash IN | |
( | |
SELECT | |
txns.hash as tx_hash | |
FROM `bigquery-public-data.crypto_bitcoin.transactions` AS txns | |
CROSS JOIN UNNEST(txns.inputs) AS inputs | |
CROSS JOIN UNNEST(txns.outputs) AS outputs | |
WHERE | |
ARRAY_TO_STRING(inputs.addresses, '') IN (SELECT address FROM shared_inputs) | |
) AND output_count = 1 | |
GROUP BY 1 | |
), | |
intersection AS ( | |
SELECT | |
miso.address | |
FROM shared_inputs | |
INNER join miso | |
ON shared_inputs.address = miso.address | |
), | |
SELECT | |
COUNT(DISTINCT ARRAY_TO_STRING(inputs.addresses, '')) AS address | |
FROM `bigquery-public-data.crypto_bitcoin.transactions` AS txns | |
, UNNEST(txns.inputs) AS inputs | |
WHERE txns.hash IN | |
( | |
SELECT | |
txns.hash as tx_hash | |
FROM `bigquery-public-data.crypto_bitcoin.transactions` AS txns | |
CROSS JOIN UNNEST(txns.inputs) AS inputs | |
WHERE | |
ARRAY_TO_STRING(inputs.addresses, '') IN (SELECT address FROM shared_inputs) | |
) | |
GROUP BY 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment