[英]How do I use SQL to return an average value for a day in a date range?
I'm trying to query the public Ethereum blockchain for gas data.我正在尝试查询公共以太坊区块链以获取气体数据。 I want my query to return the average amount of gas consumed per transaction over the course of a day, for each day since the blockchain went public to present day.我希望我的查询返回从区块链公开到今天的每一天每笔交易消耗的平均气体量。
This is my query so far:到目前为止,这是我的查询:
SELECT receipt_gas_used, block_timestamp, block_number
FROM `bigquery-public-data.crypto_ethereum.transactions`
WHERE DATE(block_timestamp) BETWEEN "2015-07-30" AND "2021-05-10"
LIMIT 2200
When I wrap the receipt_gas_used
in the AVG
function, I only get on result.当我将receipt_gas_used
包装在AVG
function 中时,我只会得到结果。 When I run the query as shown above, I get numerous results for the same day.当我运行如上所示的查询时,我在同一天得到了很多结果。 How can I write this function so that I get an average per day?我怎样才能写这个 function 以便我每天得到平均值?
I think you want:我想你想要:
SELECT DATE(block_timestamp) as date, AVG(receipt_gas_used)
FROM `bigquery-public-data.crypto_ethereum.transactions`
WHERE DATE(block_timestamp) BETWEEN '2015-07-30' AND '2021-05-10'
GROUP BY date
ORDER BY date;
You probably don't need the WHERE
clause, but I left it in.您可能不需要WHERE
子句,但我把它留在了里面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.