-->

BigQuery/ Ethereum dataset - how to write the code

2019-03-03 08:59发布

问题:

For the ethereum dataset, anyone could tell me how should I write in BigQuery if I'd know the last month transactions of a particular contract? For example, if i would know how many transactions are made in the last month for the contract address " 0x41dbecc1cdc5517c6f76f6a6e836adbee2754de3 " his a Everytime I try to analyze this address, it returns zero. For example

SELECT
  from_address,
  to_address,
  value,
  transaction_hash
FROM
  `bigquery-public-data.ethereum_blockchain.token_transfers` AS token_trs
JOIN
  `bigquery-public-data.ethereum_blockchain.contracts` AS contracts
ON
  (contracts.address = token_trs.token_address)
WHERE
  contracts.address = ' 0x41dbecc1cdc5517c6f76f6a6e836adbee2754de3 '

Please please please help me!

回答1:

You just simply took the address that exists only in one table and not in another - thus JOIN excludes it from result

You can use LEFT JOIN instead of JOIN in case if address of your interest is in one (first) table but not in another (second)

As in below example

#standardSQL
SELECT
  from_address,
  to_address,
  value,
  transaction_hash
FROM
  `bigquery-public-data.ethereum_blockchain.token_transfers` AS token_trs
LEfT JOIN
  `bigquery-public-data.ethereum_blockchain.contracts` AS contracts
ON
  (contracts.address = token_trs.token_address)
WHERE
  token_trs.token_address = '0x41dbecc1cdc5517c6f76f6a6e836adbee2754de3'   

In case if you for some reason need JOIN to work - run first below query to obtain the address that is present in both tables

#standardSQL
SELECT contracts.address
FROM `bigquery-public-data.ethereum_blockchain.token_transfers` AS token_trs
JOIN `bigquery-public-data.ethereum_blockchain.contracts` AS contracts
ON contracts.address = token_trs.token_address
LIMIT 10   

Take any address from result and run your original query with it

For example:

#standardSQL
SELECT
  from_address,
  to_address,
  value,
  transaction_hash
FROM
  `bigquery-public-data.ethereum_blockchain.token_transfers` AS token_trs
JOIN
  `bigquery-public-data.ethereum_blockchain.contracts` AS contracts
ON
  (contracts.address = token_trs.token_address)
WHERE
  contracts.address = '0x298683bd77f17bca4f3fb37b5bf02f82ee81d3ef'

Note: I see extra spaces in your address value - most likely copy paste issue but wanted to mention