您好,登錄后才能下訂單哦!
作用:返回一個字段在一個series中的變化率。
InfluxDB會計算按照時間進行排序的字段值之間的差異,并將這些結果轉化為單位變化率。其中,單位可以指定,默認為1s。
語法:
SELECT DERIVATIVE(<field_key>, [<unit>]) FROM <measurement_name> [WHERE <stuff>]
其中,unit取值可以為以下幾種:
u --microsecondss --secondsm --minutesh --hoursd --daysw --weeks
DERIVATIVE()函數還可以在GROUP BY time()的條件下與聚合函數嵌套使用,格式如下:
SELECT DERIVATIVE(AGGREGATION_FUNCTION(<field_key>),[<unit>]) FROM <measurement_name> WHERE <stuff> GROUP BY time(<aggregation_interval>)
示例:
假設location = santa_monica 條件下數據有以下幾條:
name: h3o_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.051
計算每一秒的變化率:
> SELECT DERIVATIVE(water_level) FROM h3o_feet WHERE location = 'santa_monica' LIMIT 5name: h3o_feet--------------time derivative2015-08-18T00:06:00Z 0.000144444444444444572015-08-18T00:12:00Z -0.000244444444444444652015-08-18T00:18:00Z 0.00027222222222222182015-08-18T00:24:00Z -0.0002361111111111112015-08-18T00:30:00Z 2.777777777777842e-05
第一行數據的計算公式為(2.116 - 2.064) / (360s / 1s)
計算每六分鐘的變化率
> SELECT DERIVATIVE(water_level,6m) FROM h3o_feet WHERE location = 'santa_monica' LIMIT 5name: h3o_feet--------------time derivative2015-08-18T00:06:00Z 0.0520000000000000462015-08-18T00:12:00Z -0.088000000000000082015-08-18T00:18:00Z 0.097999999999999862015-08-18T00:24:00Z -0.084999999999999962015-08-18T00:30:00Z 0.010000000000000231
第一行數據的計算過程如下:(2.116 - 2.064) / (6m / 6m)
計算每12分鐘的變化率:
> SELECT DERIVATIVE(water_level,12m) FROM h3o_feet WHERE location = 'santa_monica' LIMIT 5name: h3o_feet--------------time derivative2015-08-18T00:06:00Z 0.104000000000000092015-08-18T00:12:00Z -0.176000000000000162015-08-18T00:18:00Z 0.195999999999999732015-08-18T00:24:00Z -0.169999999999999932015-08-18T00:30:00Z 0.020000000000000462
第一行數據計算過程為:(2.116 - 2.064 / (6m / 12m)
計算每12分鐘最大值的變化率
> SELECT DERIVATIVE(MAX(water_level)) FROM h3o_feet WHERE location = 'santa_monica' AND time >= '2015-08-18T00:00:00Z' AND time < '2015-08-18T00:36:00Z' GROUP BY time(12m) name: h3o_feet--------------time derivative2015-08-18T00:12:00Z 0.0099999999999997872015-08-18T00:24:00Z -0.07499999999999973
這個函數功能非常多,也非常復雜,更多對于此功能的詳細解釋請看官網:https://docs.influxdata.com/influxdb/v0.13/query_language/functions/#derivative
作用:返回一個字段中連續的時間值之間的差異。字段類型必須是長整型或float64。
最基本的語法:
SELECT DIFFERENCE(<field_key>) FROM <measurement_name> [WHERE <stuff>]
與GROUP BY time()以及其他嵌套函數一起使用的語法格式:
SELECT DIFFERENCE(<function>(<field_key>)) FROM <measurement_name> WHERE <stuff> GROUP BY time(<time_interval>)
其中,函數可以包含以下幾個:
COUNT(), MEAN(), MEDIAN(),SUM(), FIRST(), LAST(), MIN(), MAX(), 和 PERCENTILE()。
使用示例
例子中使用的源數據如下所示:
> SELECT water_level FROM h3o_feet WHERE location='santa_monica' AND time >= '2015-08-18T00:00:00Z' and time <= '2015-08-18T00:36:00Z'name: h3o_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
計算water_level間的差異:
> SELECT DIFFERENCE(water_level) FROM h3o_feet WHERE location='santa_monica' AND time >= '2015-08-18T00:00:00Z' and time <= '2015-08-18T00:36:00Z'name: h3o_feet--------------time difference2015-08-18T00:06:00Z 0.0520000000000000462015-08-18T00:12:00Z -0.088000000000000082015-08-18T00:18:00Z 0.097999999999999862015-08-18T00:24:00Z -0.084999999999999962015-08-18T00:30:00Z 0.0100000000000002312015-08-18T00:36:00Z 0.016000000000000014
數據類型都為float類型。
作用:返回一個字段在連續的時間間隔間的差異,間隔單位可選,默認為1納秒。
語法:
SELECT ELAPSED(<field_key>, <unit>) FROM <measurement_name> [WHERE <stuff>]
示例:
計算h3o_feet字段在納秒間隔下的差異。
> SELECT ELAPSED(water_level) FROM h3o_feet WHERE location = 'santa_monica' AND time >= '2015-08-18T00:00:00Z' and time <= '2015-08-18T00:24:00Z'name: h3o_feet--------------time elapsed2015-08-18T00:06:00Z 3600000000002015-08-18T00:12:00Z 3600000000002015-08-18T00:18:00Z 3600000000002015-08-18T00:24:00Z 360000000000
在一分鐘間隔下的差異率:
> SELECT ELAPSED(water_level,1m) FROM h3o_feet WHERE location = 'santa_monica' AND time >= '2015-08-18T00:00:00Z' and time <= '2015-08-18T00:24:00Z'name: h3o_feet--------------time elapsed2015-08-18T00:06:00Z 62015-08-18T00:12:00Z 62015-08-18T00:18:00Z 62015-08-18T00:24:00Z 6
注意:如果設置的時間間隔比字段數據間的時間間隔更大時,則函數會返回0,如下所示:
> SELECT ELAPSED(water_level,1h) FROM h3o_feet WHERE location = 'santa_monica' AND time >= '2015-08-18T00:00:00Z' and time <= '2015-08-18T00:24:00Z'name: h3o_feet--------------time elapsed2015-08-18T00:06:00Z 02015-08-18T00:12:00Z 02015-08-18T00:18:00Z 02015-08-18T00:24:00Z 0
作用:返回一個連續字段值的移動平均值,字段類型必須是長×××或者float64類型。
語法:
基本語法
SELECT MOVING_AVERAGE(<field_key>,<window>) FROM <measurement_name> [WHERE <stuff>]
與其他函數和GROUP BY time()語句一起使用時的語法
SELECT MOVING_AVERAGE(<function>(<field_key>),<window>) FROM <measurement_name> WHERE <stuff> GROUP BY time(<time_interval>)
此函數可以和以下函數一起使用:
COUNT(), MEAN(),MEDIAN(), SUM(), FIRST(), LAST(), MIN(), MAX(), and PERCENTILE().
示例:
> SELECT water_level FROM h3o_feet WHERE location = 'santa_monica' AND time >= '2015-08-18T00:00:00Z' and time <= '2015-08-18T00:36:00Z'name: h3o_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
作用:返回在一個series中的一個字段中值的變化的非負速率。
語法:
SELECT NON_NEGATIVE_DERIVATIVE(<field_key>, [<unit>]) FROM <measurement_name> [WHERE <stuff>]
與聚合類函數放在一起使用時的語法如下所示:
SELECT NON_NEGATIVE_DERIVATIVE(AGGREGATION_FUNCTION(<field_key>),[<unit>]) FROM <measurement_name> WHERE <stuff> GROUP BY time(<aggregation_interval>)
此函數示例請參閱:DERIVATIVE()函數
作用:返回一個字段中的值的標準偏差。值的類型必須是長整型或float64類型。
語法:
SELECT STDDEV(<field_key>) FROM <measurement_name> [WHERE <stuff>] [GROUP BY <stuff>]
示例:
> SELECT STDDEV(water_level) FROM h3o_feet name: h3o_feet--------------time stddev1970-01-01T00:00:00Z 2.279144584196145
示例2:
> SELECT STDDEV(water_level) FROM h3o_feet WHERE time >= '2015-08-18T00:00:00Z' and time < '2015-09-18T12:06:00Z' GROUP BY time(1w), location name: h3o_feet tags: location = coyote_creek time stddev---- ------2015-08-13T00:00:00Z 2.24372630801939852015-08-20T00:00:00Z 2.1212761501447192015-08-27T00:00:00Z 3.04161221707862152015-09-03T00:00:00Z 2.53480650254352072015-09-10T00:00:00Z 2.5840039548826732015-09-17T00:00:00Z 2.2587514836274414name: h3o_feet tags: location = santa_monica time stddev---- ------2015-08-13T00:00:00Z 1.111563445875532015-08-20T00:00:00Z 1.09098492790823662015-08-27T00:00:00Z 1.98701161800969622015-09-03T00:00:00Z 1.35167784509020672015-09-10T00:00:00Z 1.49605738115005882015-09-17T00:00:00Z 1.075701669442093
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。