如何解决如何在influxdb中平均最后几天的数据
我想根据我的 influxdb 数据库中最后一天的条目计算 unit_price 的平均值。
下面显示了我最近两天的数据(每天 14 个条目) 我总共有 5 天的数据。
> select * from "variable" order by time desc limit 28
name: variable
time area_code area_name unit_price
---- --------- --------- ----------
2021-05-11T23:00:00Z P northern_Scotland 18.4695
2021-05-11T23:00:00Z N Southern_Scotland 17.598
2021-05-11T23:00:00Z M Yorkshire 16.968
2021-05-11T23:00:00Z L South_Western_England 18.6795
2021-05-11T23:00:00Z K Southern_Wales 18.081
2021-05-11T23:00:00Z J South_Eastern_England 18.501
2021-05-11T23:00:00Z H Southern_England 17.5875
2021-05-11T23:00:00Z G north_Western_England 17.4615
2021-05-11T23:00:00Z F north_Eastern_England 17.262
2021-05-11T23:00:00Z E West_Midlands 17.6085
2021-05-11T23:00:00Z D Merseyside_and_northern_Wales 19.4355
2021-05-11T23:00:00Z C London 17.4405
2021-05-11T23:00:00Z B East_Midlands 17.3565
2021-05-11T23:00:00Z A Eastern_England 17.871
2020-11-01T00:00:00Z P northern_Scotland 17.073
2020-11-01T00:00:00Z N Southern_Scotland 16.2225
2020-11-01T00:00:00Z M Yorkshire 15.6135
2020-11-01T00:00:00Z L South_Western_England 17.094
2020-11-01T00:00:00Z K Southern_Wales 16.527
2020-11-01T00:00:00Z J South_Eastern_England 16.8945
2020-11-01T00:00:00Z H Southern_England 16.128
2020-11-01T00:00:00Z G north_Western_England 16.0125
2020-11-01T00:00:00Z F north_Eastern_England 15.7395
2020-11-01T00:00:00Z E West_Midlands 16.086
2020-11-01T00:00:00Z D Merseyside_and_northern_Wales 17.8605
2020-11-01T00:00:00Z C London 15.897
2020-11-01T00:00:00Z B East_Midlands 15.8445
2020-11-01T00:00:00Z A Eastern_England 16.2855
正如您在此处看到的,limit 14 average 显示的结果与根本不使用 limit 的结果相同。 所以这个平均命令是平均“所有”数据,而不是任何有限的数据。
select mean(unit_price) from "variable" order by time desc limit 14
name: variable
time mean
---- ----
1970-01-01T00:00:00Z 16.2924375
> select mean(unit_price) from "variable"
name: variable
time mean
---- ----
1970-01-01T00:00:00Z 16.2924375
>
我尝试过嵌套选择,但似乎无法找到如何获得最后 14 个条目的平均值(或从数据的最后日期开始)
非常感谢任何帮助。
解决方法
我想我可能在玩了一些嵌套查询后已经解决了。
> select mean(unit_price) from "variable" group by time(1d) fill(none)
name: variable
time mean
---- ----
2019-04-12T00:00:00Z 15.572249999999997
2020-01-15T00:00:00Z 15.340499999999997
2020-11-01T00:00:00Z 16.377
2021-05-11T00:00:00Z 17.880000000000003
> select last("mean") from (select mean(unit_price) from "variable" group by time(1d) fill(none))
name: variable
time last
---- ----
2021-05-11T00:00:00Z 17.880000000000003
>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。