做用:返回一個字段中最大的N個值,字段類型必須是長整型或float64類型。sql
語法:bash
SELECT TOP(<field_key>[,<tag_keys>],<N>)[,<tag_keys>] FROM <measurement_name> [WHERE <stuff>] [GROUP BY <stuff>]
例子1
選擇3個water_level最大值
結果SELECT TOP(water_level,3) FROM h2o_feet
例子2name: h2o_feet -------------- time top 2015-08-29T07:18:00Z 9.957 2015-08-29T07:24:00Z 9.964 2015-08-29T07:30:00Z 9.954
選擇3個water_level最大值,並在輸出中包含相關的location標記:
SELECT TOP(water_level,3),location FROM h2o_feet
結果
name: h2o_feet -------------- time top location 2015-08-29T07:18:00Z 9.957 coyote_creek 2015-08-29T07:24:00Z 9.964 coyote_creek 2015-08-29T07:30:00Z 9.954 coyote_creek
例子3
選擇在2個location標籤的最大值
SELECT TOP(water_level,location,2) FROM h2o_feet
結果
name: h2o_feet -------------- time top location 2015-08-29T03:54:00Z 7.205 santa_monica 2015-08-29T07:24:00Z 9.964 coyote_creek
輸出顯示的位置每一個標籤值water_level最高值(santa_monica和coyote_creek)。
注:查詢語法SELECT TOP(<field_key>,<tag_key>,<N>),標籤在哪裏有X的不一樣的值,返回n或x字段的值,以較小者爲準,並返回的每一個點有一個獨特的標籤值。要演示這種行爲,請參見上面示例查詢的結果,其中n等於3,n等於1。
N
= 3
SELECT TOP(water_level,location,3) FROM h2o_feet
結果
name: h2o_feet -------------- time top location 2015-08-29T03:54:00Z 7.205 santa_monica 2015-08-29T07:24:00Z 9.964 coyote_creek
返回兩個值而不是三InfluxDB由於位置標籤只有兩個值(santa_monica和coyote_creek)。
N
= 1
結果SELECT TOP(water_level,location,1) FROM h2o_feet
name: h2o_feet -------------- time top location 2015-08-29T07:24:00Z 9.964 coyote_creek
比較water_level InfluxDB頂值在每一個標籤的位置值並返回water_level的較大值。
例子4
選擇最大water_level 2個值,範圍2015年8月18日 4點與2015年8月18日4點18分,範圍每一個location標籤
結果SELECT TOP(water_level,2) FROM h2o_feet WHERE time >= '2015-08-18T04:00:00Z' AND time < '2015-08-18T04:24:00Z' GROUP BY location
例子5
選擇wtaer_level最大的2個值,在name: h2o_feet tags: location=coyote_creek time top ---- --- 2015-08-18T04:00:00Z 2.943 2015-08-18T04:06:00Z 2.831 name: h2o_feet tags: location=santa_monica time top ---- --- 2015-08-18T04:06:00Z 4.055 2015-08-18T04:18:00Z 4.124範圍2015年8月18日 4點與2015年8月18日4點18分,location爲santa_monica
SELECT TOP(water_level,2) FROM h2o_feet WHERE time >= '2015-08-18T04:00:00Z' AND time < '2015-08-18T04:24:00Z' AND location = 'santa_monica'
值得注意的是原始數據,water_level等於4.055在2015-08-18t04:06:00z和2015-08-18t04:12:00z。在相同的狀況下,InfluxDB返回值更早的那個時間戳。name: h2o_feet -------------- time top 2015-08-18T04:06:00Z 4.055 2015-08-18T04:18:00Z 4.124
做用:返回一個字段中最小的N個值。字段類型必須是長整型或float64類型。less
語法:函數
SELECT BOTTOM(<field_key>[,<tag_keys>],<N>)[,<tag_keys>] FROM <measurement_name> [WHERE <stuff>] [GROUP BY <stuff>]
例子1
選擇三個最小值
結果SELECT BOTTOM(water_level,3) FROM h2o_feet
例子2
選擇三個最小值,在輸出中包含相關的location標籤:name: h2o_feet -------------- time bottom 2015-08-29T14:30:00Z -0.61 2015-08-29T14:36:00Z -0.591 2015-08-30T15:18:00Z -0.594
SELECT BOTTOM(water_level,3),location FROM h2o_feet
name: h2o_feet -------------- time bottom location 2015-08-29T14:30:00Z -0.61 coyote_creek 2015-08-29T14:36:00Z -0.591 coyote_creek 2015-08-30T15:18:00Z -0.594 coyote_creek
例子3
選擇2個location最小值
結果SELECT BOTTOM(water_level,location,2) FROM h2o_feet
輸出顯示的位置每一個標籤值water_level底值(santa_monica和coyote_creek)。
注:查詢語法select(< field_key >,< tag_key >,<n>),標籤在哪裏有X的不一樣的值,返回n或x字段的值,以較小者爲準,並返回的每一個點有一個獨特的標籤值。要演示這種行爲,請參見上面示例查詢的結果,其中n等於3,n等於1。
= name: h2o_feet -------------- time bottom location 2015-08-29T10:36:00Z -0.243 santa_monica 2015-08-29T14:30:00Z -0.61 coyote_creekN3
結果SELECT BOTTOM(water_level,location,3) FROM h2o_feet
name: h2o_feet -------------- time bottom location 2015-08-29T10:36:00Z -0.243 santa_monica 2015-08-29T14:30:00Z -0.61 coyote_creek
返回兩個值而不是三InfluxDB由於位置標籤只有兩個值(santa_monica和coyote_creek)。
N
= 1
結果SELECT BOTTOM(water_level,location,1) FROM h2o_feet
name: h2o_feet -------------- time bottom location 2015-08-29T14:30:00Z -0.61 coyote_creek
InfluxDB比較water_level底值在每一個標籤的位置值並返回water_level值越小。
例子4
選擇兩個最小值 ,範圍在2015年8月18日4點和2015年8月18日4點18分。每一個location標籤
SELECT BOTTOM(water_level,2) FROM h2o_feet WHERE time >= '2015-08-18T04:00:00Z' AND time < '2015-08-18T04:24:00Z' GROUP BY location
例子5
選擇最小的兩個值,在2015年8月18日4點和2015年8月18日4點18分,location爲santa_monica
name: h2o_feet tags: location=coyote_creek time bottom ---- ------ 2015-08-18T04:12:00Z 2.717 2015-08-18T04:18:00Z 2.625 name: h2o_feet tags: location=santa_monica time bottom ---- ------ 2015-08-18T04:00:00Z 3.911 2015-08-18T04:06:00Z 4.055
SELECT BOTTOM(water_level,2) FROM h2o_feet WHERE time >= '2015-08-18T04:00:00Z' AND time < '2015-08-18T04:24:00Z' AND location = 'santa_monica'
結果
name: h2o_feet -------------- time bottom 2015-08-18T04:00:00Z 3.911 2015-08-18T04:06:00Z 4.055
值得注意的是原始數據,water_level等於4.055在2015-08-18t04:06:00z和2015-08-18t04:12:00z。在相同的狀況下,InfluxDB返回值更早的那個時間戳。
做用:返回一個字段中最老的取值。spa
語法:code
例子1
選擇locaction 爲santa_monica,water_level最老的值
SELECT FIRST(water_level) FROM h2o_feet WHERE location = 'santa_monica'
結果
SELECT FIRST(<field_key>)[,<tag_key(s)>] FROM <measurement_name> [WHERE <stuff>] [GROUP BY <stuff>]
name: h2o_feet -------------- time first 2015-08-18T00:00:00Z 2.064
例子2
選擇最老的water_level,2015-08-18T00:42:00Z
與2015-08-18T00:54:00Z之間,並輸出location tag
2015-08-18T00:42:00Z2015-08-18T00:54:00Z之間,並輸出location tag
SELECT FIRST(water_level),location FROM h2o_feet WHERE time >= '2015-08-18T00:42:00Z' and time <= '2015-08-18T00:54:00Z'
結果
結果
name: h2o_feet -------------- time first location 2015-08-18T00:42:00Z 7.234 coyote_creek
例子3
選擇最老的water_level,以location分組
SELECT FIRST(water_level) FROM h2o_feet GROUP BY location
結果
name: h2o_feet tags: location = coyote_creek time first ---- ----- 2015-08-18T00:00:00Z 8.12 name: h2o_feet tags: location = santa_monica time first ---- ----- 2015-08-18T00:00:00Z 2.064
做用:返回一個字段中最新的取值。排序
語法:flux
SELECT LAST(<field_key>)[,<tag_key(s)>] FROM <measurement_name> [WHERE <stuff>] [GROUP BY <stuff>]
例子1
以location爲santa_monica爲條件,選擇最新的water_level
結果SELECT LAST(water_level) FROM h2o_feet WHERE location = 'santa_monica'
例子2
在 與 name: h2o_feet -------------- time last 2015-09-18T21:42:00Z 4.9382015-08-18T00:42:00Z2015-08-18T00:54:00Z之間,選擇最新的water_level,並輸出location tag
SELECT LAST(water_level),location FROM h2o_feet WHERE time >= '2015-08-18T00:42:00Z' and time <= '2015-08-18T00:54:00Z'
結果
name: h2o_feet -------------- time last location 2015-08-18T00:54:00Z 6.982 coyote_creek
例子2
選擇最新的water_level,以location分組
結果SELECT LAST(water_level) FROM h2o_feet GROUP BY location
name: h2o_feet tags: location = coyote_creek time last ---- ---- 2015-09-18T16:24:00Z 3.235 name: h2o_feet tags: location = santa_monica time last ---- ---- 2015-09-18T21:42:00Z 4.938
Note:LAST()
does not return points that occur afternow()
unless theWHERE
clause specifies that time range. See Frequently Encountered Issues for how to query afternow()
.
LAST()now()WHEREnow()
做用:返回一個字段中的最大值。該字段類型必須是長整型,float64,或布爾類型。ci
語法:rem
SELECT MAX(<field_key>)[,<tag_key(s)>] FROM <measurement_name> [WHERE <stuff>] [GROUP BY <stuff>]
例子1
選擇表h2o_feet中最大的值water_level
結果SELECT MAX(water_level) FROM h2o_feet
name: h2o_feet -------------- time max 2015-08-29T07:24:00Z 9.964
例子2
選擇表h2o_feet中最大的值water_level,並輸出location tag
SELECT MAX(water_level),location FROM h2o_feet
結果
name: h2o_feet -------------- time max location 2015-08-29T07:24:00Z 9.964 coyote_creek
例子3
每12分選擇表h2o_feet中每一個location最大的值water_level,指定的時間範圍
SELECT MAX(water_level) FROM h2o_feet WHERE time >= '2015-08-18T00:00:00Z' AND time < '2015-08-18T00:54:00Z' GROUP BY time(12m), location
name: h2o_feet tags: location = coyote_creek time max ---- --- 2015-08-18T00:00:00Z 8.12 2015-08-18T00:12:00Z 7.887 2015-08-18T00:24:00Z 7.635 2015-08-18T00:36:00Z 7.372 2015-08-18T00:48:00Z 7.11 name: h2o_feet tags: location = santa_monica time max ---- --- 2015-08-18T00:00:00Z 2.116 2015-08-18T00:12:00Z 2.126 2015-08-18T00:24:00Z 2.051 2015-08-18T00:36:00Z 2.067 2015-08-18T00:48:00Z 1.991
做用:返回一個字段中的最小值。該字段類型必須是長整型,float64,或布爾類型。
語法:
SELECT MIN(<field_key>)[,<tag_key(s)>] FROM <measurement_name> [WHERE <stuff>] [GROUP BY <stuff>]
例子1
選擇表h2o_feet中最小的值water_level
SELECT MIN(water_level) FROM h2o_feet
結果
name: h2o_feet -------------- time min 2015-08-29T14:30:00Z -0.61
例子2
選擇表h2o_feet中最小的值water_level,並輸出location tag
結果SELECT MIN(water_level),location FROM h2o_feet
name: h2o_feet -------------- time min location 2015-08-29T14:30:00Z -0.61 coyote_creek
例子3
每12分選擇表h2o_feet中每一個location最小的值water_level,指定的時間範圍
SELECT MIN(water_level) FROM h2o_feet WHERE time >= '2015-08-18T00:00:00Z' AND time < '2015-08-18T00:54:00Z' GROUP BY time(12m), location
結果
name: h2o_feet tags: location = coyote_creek time min ---- --- 2015-08-18T00:00:00Z 8.005 2015-08-18T00:12:00Z 7.762 2015-08-18T00:24:00Z 7.5 2015-08-18T00:36:00Z 7.234 2015-08-18T00:48:00Z 7.11 name: h2o_feet tags: location = santa_monica time min ---- --- 2015-08-18T00:00:00Z 2.064 2015-08-18T00:12:00Z 2.028 2015-08-18T00:24:00Z 2.041 2015-08-18T00:36:00Z 2.057 2015-08-18T00:48:00Z 1.991
做用:返回排序值排位爲N的百分值。字段的類型必須是長整型或float64。
百分值是介於100到0之間的整數或浮點數,包括100。
語法:
例子1
計算location爲coyote_creek,排位爲5%的water_level值。SELECT PERCENTILE(<field_key>, <N>)[,<tag_key(s)>] FROM <measurement_name> [WHERE <stuff>] [GROUP BY <stuff>]
SELECT PERCENTILE(water_level,5) FROM h2o_feet WHERE location = 'coyote_creek'
結果
: h2o_feet -------------- time percentile 2015-09-09T11:42:00Z 1.148
解釋:
就是將water_level字段按照不一樣的location求百分比,而後取第五位數據。
值1.148大於5%的位置的值(The value1.148
is larger than 5% of the values inwater_level
wherelocation
equalscoyote_creek
.)1.148water_levellocationcoyote_creek
例子2
計算location爲coyote_creek,排位爲5%的water_level值,並輸出location tag。
結果SELECT PERCENTILE(water_level,5),location FROM h2o_feet
name: h2o_feet -------------- time percentile location 2015-08-28T12:06:00Z 1.122 santa_monica
例子2
計算以location分組,排在100%的值
SELECT PERCENTILE(water_level, 100) FROM h2o_feet GROUP BY location
結果
name: h2o_feet tags: location = coyote_creek time percentile ---- ---------- 2015-08-29T07:24:00Z 9.964 name: h2o_feet tags: location = santa_monica time percentile ---- ---------- 2015-08-29T03:54:00Z 7.205
注意:PERCENTILE(<field_key>,100)至關於MAX(<field_key>)
目前,PERCENTILE(<field_key>,0)不至關於MIN(<field_key>)
注意,PERCENTILE(<field_key>, 50)接近於MEDIAN(),MEDIAN()若是是偶婁個則返回中間兩個值的平均值
詳細資料可參考官網:https://docs.influxdata.com/influxdb/v1.3/query_language/functions