BigQuery/ Ethereum dataset - how to write the code

拥有回忆 提交于 2019-12-02 12:02:24

问题


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



来源:https://stackoverflow.com/questions/53143808/bigquery-ethereum-dataset-how-to-write-the-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!