简体   繁体   English

如何使用 SQL 返回日期范围内一天的平均值?

[英]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.

相关问题 如何返回最大滚动平均值的日期范围? - How do I return the date range of a max rolling average value? 使用SQL返回日期范围内每天的所有未使用信息 - Use SQL to return all unused information for each day in date range 如何在 Access SQL 中使用 BETWEEN 和 AND 来过滤日期范围? - How do I use BETWEEN and AND in Access SQL to filter on a date range? 如何在MS SQL中查询给定日期范围内的“每天”结果? - How Do I Query for “Per Day” results for a given date range in MS SQL? SQL - 获取日期范围内的平均值 - SQL - Getting average value across date range 如何在Postgres SQL中返回日期值? - How do I return a date value in postgres sql? 完成:对于Z家公司,计算X天内A的平均值。 现在,我如何:对于平均A最高的公司,第X天B的返回值? - Done: for Z companies, calculate average value of A over X days. How do I now: return value of B for day X for company with highest average of A? SQL-如何在日期范围之间为每个日期仅返回一个条目? - SQL- How do I return just one entry for each date between a date range? 如何获取SQL中列的平均日期间隔? - How do I get the average date interval of a column in SQL? 如何在SQL中的某个日期范围内执行移动平均线? - How to do a moving average on a range of dates in SQL?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM