clickhouse查询语句操作笔记

SELECT
  --*
  --aa."IP地址" AS "IP地址"
      aa."IP地址" AS "IP地址",
      aa."指标名称" AS "指标名称",
      aa."设备类型" AS "设备类型",
      aa."设备名称" AS "设备名称",
      aa."指标项名称" AS "指标项名称",
      aa."监测点名称" AS "监测点名称",
      aa."监测点分类" AS "监测点分类",
      aa."单位" AS "单位",
      aa."分组名称" AS "分组名称",
      aa."数据类型" AS "数据类型",
      aa."指标值" AS "内存使用率(%)",
      bb."指标值" AS "CPU使用率(%)",
      cc."指标值" AS "磁盘使用率(%)",
      dd."指标值" AS "Ping成功率(%)"
FROM
  (
    SELECT
      view_1."IP地址",
      view_1."指标名称",
      view_1."设备类型",
      view_1."设备名称",
      view_1."指标项名称",
      view_1."监测点名称",
      view_1."监测点分类",
      view_1."单位",
      view_1."分组名称",
      view_1."数据类型",
      ROUND(argMax(view_1."指标值", view_1."_cw_raw_time"),2) AS "指标值"
    FROM
      "cw_db"."monitor_MxPerformanceData" AS view_1
    WHERE
      "_cw_raw_time" > toUInt64(NOW()) * 1000 - 200000
      AND view_1."指标名称" = '内存使用率'
      AND view_1."设备类型" = 'Agent Linux'
      AND view_1."指标项名称" = 'usage'
    GROUP BY
      view_1."IP地址",
      view_1."指标名称",
      view_1."设备类型",
      view_1."设备名称",
      view_1."指标项名称",
      view_1."监测点名称",
      view_1."监测点分类",
      view_1."单位",
      view_1."分组名称",
      view_1."数据类型"
  ) aa
  LEFT JOIN (
    SELECT
      view_1."IP地址",
      view_1."指标名称",
      ROUND(argMax(view_1."指标值", view_1."_cw_raw_time"),2) AS "指标值"
    FROM
      "cw_db"."monitor_MxPerformanceData" AS view_1
    WHERE
      "_cw_raw_time" > toUInt64(NOW()) * 1000 - 200000
      AND view_1."指标名称" = 'CPU使用率'
      AND view_1."设备类型" = 'Agent Linux'
      AND view_1."指标项名称" = 'usage'
    GROUP BY
      view_1."IP地址",
      view_1."指标名称"
  ) bb
  ON aa."IP地址" = bb."IP地址"
  LEFT JOIN (
    SELECT
      view_1."IP地址",
      view_1."指标名称",
      ROUND(argMax(view_1."指标值", view_1."_cw_raw_time"),2) AS "指标值"
    FROM
      "cw_db"."monitor_MxPerformanceData" AS view_1
    WHERE
      "_cw_raw_time" > toUInt64(NOW()) * 1000 - 200000
      AND view_1."指标名称" = '磁盘使用率'
      AND view_1."设备类型" = 'Agent Linux'
      AND view_1."指标项名称" = 'usage'
        GROUP BY
      view_1."IP地址",
      view_1."指标名称"
  ) cc
  ON aa."IP地址" = cc."IP地址"
   LEFT JOIN (
    SELECT
      view_1."IP地址",
      view_1."指标名称",
      ROUND(argMax(view_1."指标值", view_1."_cw_raw_time"),2) AS "指标值"
    FROM
      "cw_db"."monitor_MxPerformanceData" AS view_1
    WHERE
      "_cw_raw_time" > toUInt64(NOW()) * 1000 - 200000
      AND view_1."监测点分类" = 'Ping'
      AND view_1."设备类型" = 'Agent Linux'
      AND view_1."指标项名称" = 'successrate'
        GROUP BY
      view_1."IP地址",
      view_1."指标名称"
  ) dd
  ON aa."IP地址" = dd."IP地址"

你可能感兴趣的:(clickhouse,笔记,数据库)