- drop 、set、rename应该放最语句后端
- join 只能连接两个表
- union 可以并多个表
- pivot 可以做行专列
- filter用or比contains 快N倍
- range显示起止时间可以加快查询速度
t_max = from(bucket: "po")
|> range(start: 2022-02-01T00:00:00Z, stop: 2022-03-01T00:00:00Z)
|> filter(fn: (r) => r["tag_id_2022-02"] == "c1.H_1AH1_PM5350P_1\\MHAI1\\ThdA\\phsA" or r["tag_id_2022-02"] == "c1.H_1AH1_PM5350P_1\\MHAI1\\ThdA\\phsB" or r["tag_id_2022-02"] == "c1.H_1AH1_PM5350P_1\\MHAI1\\ThdA\\phsC")
|> set(key: "tag", value: "max")
|> group(columns: ["tag_id_2022-02"])
|> window(every: 1mo)
|> max()
//|> rename(columns: { _value: "max"})
|> drop(columns: ["_time", "_start","_stop","_field","_measurement","table"])
t_min = from(bucket: "po")
|> range(start: 2022-02-01T00:00:00Z, stop: 2022-03-01T00:00:00Z)
|> filter(fn: (r) => r["tag_id_2022-02"] == "c1.H_1AH1_PM5350P_1\\MHAI1\\ThdA\\phsA" or r["tag_id_2022-02"] == "c1.H_1AH1_PM5350P_1\\MHAI1\\ThdA\\phsB" or r["tag_id_2022-02"] == "c1.H_1AH1_PM5350P_1\\MHAI1\\ThdA\\phsC")
|> set(key: "tag", value: "min")
|> group(columns: ["tag_id_2022-02"])
|> window(every: 1mo)
|> min()
//|> rename(columns: { _value: "min"})
|> drop(columns: ["_time", "_start","_stop","_field","_measurement","table"])
t_mean = from(bucket: "po")
|> range(start: 2022-02-01T00:00:00Z, stop: 2022-03-01T00:00:00Z)
|> filter(fn: (r) => r["tag_id_2022-02"] == "c1.H_1AH1_PM5350P_1\\MHAI1\\ThdA\\phsA" or r["tag_id_2022-02"] == "c1.H_1AH1_PM5350P_1\\MHAI1\\ThdA\\phsB" or r["tag_id_2022-02"] == "c1.H_1AH1_PM5350P_1\\MHAI1\\ThdA\\phsC")
//|> filter(fn: (r) =>contains(value: r["tag_id_2022-01"], set: ["c1.H_1AH1_PM5350P_1\\MHAI1\\ThdA\\phsA"]))
|> group(columns: ["tag_id_2022-02"])
|> window(every: 1mo)
|> mean()
|> drop(columns: [ "_start","_stop","_field","_measurement"])
|> set(key: "tag", value: "mean")
t_last = from(bucket: "po")
|> range(start: 2022-02-01T00:00:00Z, stop: 2022-03-01T00:00:00Z)
|> filter(fn: (r) => r["tag_id_2022-02"] == "c1.H_1AH1_PM5350P_1\\MHAI1\\ThdA\\phsA" or r["tag_id_2022-02"] == "c1.H_1AH1_PM5350P_1\\MHAI1\\ThdA\\phsB" or r["tag_id_2022-02"] == "c1.H_1AH1_PM5350P_1\\MHAI1\\ThdA\\phsC")
|> set(key: "tag", value: "last")
|> group(columns: ["tag_id_2022-02"])
|> window(every: 1mo)
|> last()
|> drop(columns: ["_time", "_start","_stop","_field","_measurement","table"])
union(tables: [t_max,t_min,t_last,t_mean])
|>pivot(rowKey: ["tag_id_2022-02"], columnKey: ["tag"], valueColumn: "_value")
标签:02,Union,ThdA,PM5350P,语法,Flux,tag,2022,id
From: https://www.cnblogs.com/wuhailong/p/16624268.html