日本熟妇hd丰满老熟妇,中文字幕一区二区三区在线不卡 ,亚洲成片在线观看,免费女同在线一区二区

子查詢

更新時間:

子查詢是嵌套在另一個查詢的FROM子句中的查詢。使用子查詢將查詢作為條件應用在另一個查詢中。子查詢提供類似嵌套函數和SQL HAVING子句的功能。

語法

  1. SELECT_clause FROM ( SELECT_statement ) [...]

語法描述

TSDB For InfluxDB?首先執行子查詢,然后執行主查詢。

主查詢包含著子查詢,至少需要SELECT子句和FROM子句。主查詢支持本文檔中列出的所有子句。

子查詢在主查詢的FROM子句中,需要用括號將子查詢括起來。子查詢支持本文檔中列出的所有子句。

InfluxQL支持在主查詢中有多個嵌套的子查詢,示例語法如下:

  1. SELECT_clause FROM ( SELECT_clause FROM ( SELECT_statement ) [...] ) [...]

示例

計算多個MAX()值的SUM()

  1. > SELECT SUM("max") FROM (SELECT MAX("water_level") FROM "h2o_feet" GROUP BY "location")
  2. name: h2o_feet
  3. time sum
  4. ---- ---
  5. 1970-01-01T00:00:00Z 17.169

該查詢返回每個locationwater_level的最大值的總和。

TSDB For InfluxDB?首先執行子查詢,計算每個locationwater_level的最大值:

  1. > SELECT MAX("water_level") FROM "h2o_feet" GROUP BY "location"
  2. name: h2o_feet
  3. tags: location=coyote_creek
  4. time max
  5. ---- ---
  6. 2015-08-29T07:24:00Z 9.964
  7. name: h2o_feet
  8. tags: location=santa_monica
  9. time max
  10. ---- ---
  11. 2015-08-29T03:54:00Z 7.205

然后,TSDB For InfluxDB?執行主查詢,計算這些最大值的總和:9.964 + 7.205 = 17.169。請注意,該主查詢指定max(而不是water_level)作為SUM()函數中的field key。

計算兩個field的差值的MEAN()

  1. > SELECT MEAN("difference") FROM (SELECT "cats" - "dogs" AS "difference" FROM "pet_daycare")
  2. name: pet_daycare
  3. time mean
  4. ---- ----
  5. 1970-01-01T00:00:00Z 1.75

該查詢返回measurement pet_daycarecats數量和dogs數量的差異的平均值。

TSDB For InfluxDB?首先執行子查詢,計算field cats中的值和field dogs中的值的差異,并將輸出列命名為difference

  1. > SELECT "cats" - "dogs" AS "difference" FROM "pet_daycare"
  2. name: pet_daycare
  3. time difference
  4. ---- ----------
  5. 2017-01-20T00:55:56Z -1
  6. 2017-01-21T00:55:56Z -49
  7. 2017-01-22T00:55:56Z 66
  8. 2017-01-23T00:55:56Z -9

然后,TSDB For InfluxDB?執行主查詢,計算這些差值的平均值。請注意,該主查詢指定difference作為MEAN()函數中的field key。

計算多個MEAN()值并在這些值上加上條件

  1. > SELECT "all_the_means" FROM (SELECT MEAN("water_level") AS "all_the_means" FROM "h2o_feet" WHERE time >= '2015-08-18T00:00:00Z' AND time <= '2015-08-18T00:30:00Z' GROUP BY time(12m) ) WHERE "all_the_means" > 5
  2. name: h2o_feet
  3. time all_the_means
  4. ---- -------------
  5. 2015-08-18T00:00:00Z 5.07625

該查詢返回water_level的所有大于5的平均值。

TSDB For InfluxDB?首先執行子查詢,計算從2015-08-18T00:00:00Z2015-08-18T00:30:00Z water_level的平均值,并將結果按12分鐘的時間間隔進行分組,同時將輸出列命名為all_the_means

  1. > SELECT MEAN("water_level") AS "all_the_means" FROM "h2o_feet" WHERE time >= '2015-08-18T00:00:00Z' AND time <= '2015-08-18T00:30:00Z' GROUP BY time(12m)
  2. name: h2o_feet
  3. time all_the_means
  4. ---- -------------
  5. 2015-08-18T00:00:00Z 5.07625
  6. 2015-08-18T00:12:00Z 4.950749999999999
  7. 2015-08-18T00:24:00Z 4.80675

然后,TSDB For InfluxDB?執行主查詢,只返回那些大于5的平均值。請注意,該主查詢指定all_the_means作為SELECT子句中的field key。

計算多個DERIVATIVE()值的SUM()

  1. > SELECT SUM("water_level_derivative") AS "sum_derivative" FROM (SELECT DERIVATIVE(MEAN("water_level")) AS "water_level_derivative" FROM "h2o_feet" WHERE time >= '2015-08-18T00:00:00Z' AND time <= '2015-08-18T00:30:00Z' GROUP BY time(12m),"location") GROUP BY "location"
  2. name: h2o_feet
  3. tags: location=coyote_creek
  4. time sum_derivative
  5. ---- --------------
  6. 1970-01-01T00:00:00Z -0.4950000000000001
  7. name: h2o_feet
  8. tags: location=santa_monica
  9. time sum_derivative
  10. ---- --------------
  11. 1970-01-01T00:00:00Z -0.043999999999999595

該查詢返回每個locationwater_level的平均值的導數之和。

TSDB For InfluxDB?首先執行子查詢,計算以12分鐘為間隔獲取的water_level的平均值的導數,它對每個location都進行了計算,并將輸出列命名為water_level_derivative

  1. > SELECT DERIVATIVE(MEAN("water_level")) AS "water_level_derivative" FROM "h2o_feet" WHERE time >= '2015-08-18T00:00:00Z' AND time <= '2015-08-18T00:30:00Z' GROUP BY time(12m),"location"
  2. name: h2o_feet
  3. tags: location=coyote_creek
  4. time water_level_derivative
  5. ---- ----------------------
  6. 2015-08-18T00:12:00Z -0.23800000000000043
  7. 2015-08-18T00:24:00Z -0.2569999999999997
  8. name: h2o_feet
  9. tags: location=santa_monica
  10. time water_level_derivative
  11. ---- ----------------------
  12. 2015-08-18T00:12:00Z -0.0129999999999999
  13. 2015-08-18T00:24:00Z -0.030999999999999694

然后,TSDB For InfluxDB?執行主查詢,計算每個locationwater_level_derivative的總和。請注意,該主查詢指定water_level_derivative(而不是water_levelderivative)作為SUM()函數中的field key。

子查詢的常見問題

在子查詢中有多個SELECT語句

InfluxQL支持在主查詢中有多個嵌套的子查詢:

  1. SELECT_clause FROM ( SELECT_clause FROM ( SELECT_statement ) [...] ) [...]
  2. ------------------ ----------------
  3. Subquery 1 Subquery 2

InfluxQL不支持在子查詢中有多個SELECT語句:

  1. SELECT_clause FROM (SELECT_statement; SELECT_statement) [...]

如果在子查詢中有多個SELECT語句,那么系統會返回解析錯誤。


InfluxDB? is a trademark registered by InfluxData, which is not affiliated with, and does not endorse, TSDB for InfluxDB?.