【发布时间】:2021-07-24 06:32:12
【问题描述】:
select host, time as currentTime, floor((1 - (
select sum(measure_value::double)
from "DendroTimestreamDB"."hostMetrics"
where cpuMode = 'idle'
and time <= h.time
group by host
) / ((
select sum(measure_value::double)
from "DendroTimestreamDB"."hostMetrics"
where cpuMode = 'idle'
and time <= h.time
group by host
) + (
select sum(measure_value::double)
from "DendroTimestreamDB"."hostMetrics"
where cpuMode = 'system'
and time <= h.time
group by host
) + (
select sum(measure_value::double)
from "DendroTimestreamDB"."hostMetrics"
where cpuMode = 'user'
and time <= h.time
group by host
))) * 100) as utilization
from "DendroTimestreamDB"."hostMetrics" h
group by host, time
返回错误line 20:3: Given correlated subquery is not supported 但根据Timestream subquery support
Timestream 查询语言支持相关子查询和其他子查询。
列:
cpu模式, 主持人, 设备, 处理器代码, 集电极, measure_value::double, 测量名称, 时间,
样本数据:
空闲,MacBook-Pro.local,-,0,cpu,115950.13,cpu_seconds_total,2021-04-29 13:46:11.000000000
期望的输出:
主持人, 时间, 利用率
MacBook-Pro.local 2021-04-29 13:47:56.000000000 15
MacBook-Pro.local 2021-04-29 13:47:41.000000000 16
MacBook-Pro.local 2021-04-29 13:47:26.000000000 19
我正在尝试使用公式 (1 - idleTime / totalTime) * 100 计算 CPU 利用率,但显然不支持这些相关的子查询。我只需要以不同的方式重写它吗?
在求和子查询中,我试图计算在主查询之前收到的度量值的总和,我正在使用 and time <= h.time 行来执行此操作,从而使查询相互关联,因此问题。
非常感谢
【问题讨论】:
-
请提供样本数据、预期结果和逻辑解释。
标签: sql amazon-web-services time-series amazon-timestream