云日志服务 LTS-SQL JOIN语法:示例

时间:2024-07-04 10:52:12

示例

有两个表,access表示主机的接入指标包含路径,时延,状态码,host为主机指标包含cpu和内存。通过JOIN可以关联接入和主机指标,查看相同主机的不同维度的指标情况。
  • LEFT JOIN
    1. 查询语句
      SELECT
      	"access".__time,
      	"access".host_ip,
      	"access".cost,
      	"host".cpu,
      	"host".memory
      FROM
      	log "access"
      	LEFT JOIN (select memory,cpu,host_ip from log) host ON "access".host_ip = "host".host_ip
    2. 返回结果,总共60条数据。
  • RIGHT JOIN
    1. 查询语句
      SELECT
      	"access".__time,
      	"host".host_ip,
      	"access".cost,
      	"host".cpu,
      	"host".memory
      FROM
      	log "access"
      	RIGHT  JOIN (select memory,cpu,host_ip from log) host ON "access".host_ip = "host".host_ip
    2. 返回结果,总共60条数据。
  • INNER JOIN
    1. 查询语句
      SELECT
      	"access".__time,
      	"host".host_ip,
      	"access".cost,
      	"host".cpu,
      	"host".memory
      FROM
      	log "access"
      	INNER  JOIN (select memory,cpu,host_ip from log) host ON "access".host_ip = "host".host_ip
    2. 返回结果,总共45条数据。
support.huaweicloud.com/usermanual-lts/lts_sql_0025.html