• Flux Union语法


    • 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")
    
  • 相关阅读:
    探讨SQL Server并发处理存在就更新七种解决方案
    集合随机打乱
    订单并发5000的排队机制
    10款面向HTML5 画布(Canvas)的JavaScript库
    抽象类和接口的区别以及使用场景(记)
    常用的正则表达式
    webview加载url出现空白页面,有些页面没问题
    SQL常用语句
    Android Studio 简单介绍和使用问题小结
    Android中获取应用程序(包)的信息-----PackageManager的使用(一)
  • 原文地址:https://www.cnblogs.com/wuhailong/p/16624268.html
Copyright © 2020-2023  润新知