4. Moving_average () function
Function: Returns the moving average of a continuous field value, which must be a long or float64 type.
Example 1:
The following examples water_level
are shown in tables h2o_feet,
location 为
santa_monica,
时间段
2015-08-18-t00:00:00z and 2015-08-18-t00:36:00z:
> SELECT water_level FROM h2o_feet WHERE location = ‘santa_monica‘ AND time >= ‘2015-08-18T00:00:00Z‘ and time <= ‘2015-08-18T00:36:00Z‘name: h2o_feet--------------time water_level2015-08-18T00:00:00Z 2.0642015-08-18T00:06:00Z 2.1162015-08-18T00:12:00Z 2.0282015-08-18T00:18:00Z 2.1262015-08-18T00:24:00Z 2.0412015-08-18T00:30:00Z 2.0512015-08-18T00:36:00Z 2.067
计算移动平均在每2字段值:
SELECT MOVING_AVERAGE(water_level,2) FROM h2o_feet WHERE location = ‘santa_monica‘ AND time >= ‘2015-08-18T00:00:00Z‘ and time <= ‘2015-08-18T00:36:00Z‘
结果:
name: h2o_feet--------------time moving_average2015-08-18T00:06:00Z 2.092015-08-18T00:12:00Z 2.0722015-08-18T00:18:00Z 2.0772015-08-18T00:24:00Z 2.08352015-08-18T00:30:00Z 2.04600000000000032015-08-18T00:36:00Z 2.059
解释
移动平均线列中的第一个值的平均值是2.064和2.116,第二个移动平均线列中的值是2.116和2.028的平均水平。
例子2
- Select the lowest value water_level every 12 minutes and calculate the moving average per 2 field value:
SELECT MOVING_AVERAGE(MIN(water_level),2) FROM h2o_feet WHERE location = ‘santa_monica‘ AND time >= ‘2015-08-18T00:00:00Z‘ and time <= ‘2015-08-18T00:36:00Z‘ GROUP BY time(12m)
结果:
name: h2o_feet--------------time moving_average2015-08-18T00:12:00Z 2.04600000000000032015-08-18T00:24:00Z 2.03450000000000042015-08-18T00:36:00Z 2.0540000000000003
解释:
这些结果,InfluxDB首先选择MIN()
water_level
每12分钟间隔:
name: h2o_feet--------------time min2015-08-18T00:00:00Z 2.0642015-08-18T00:12:00Z 2.0282015-08-18T00:24:00Z 2.0412015-08-18T00:36:00Z 2.067
然后使用这些值来计算移动平均在每2字段值,移动平均线列中的第一个结果的平均值2.064和2.028,第二个结果是2.028和2.041的平均水平。
InfluxDB Transform class functions