鉴于此查询及其输出,我想对所有具有相同时间戳的值求和(在这种情况下,这三个值在2018-08-28T22:57:19.949
处出现)。
SELECT d from (select non_negative_derivative(f64, 1m) as d
FROM _
WHERE __name__='rx_bytes' and dp_id='0x7'
GROUP BY port_name)
WHERE d > 0
name: _
time d
---- -
2018-08-28T22:57:09.586Z 12209.302325581395
2018-08-28T22:57:10.558Z 12962.962962962964
2018-08-28T22:57:19.949Z 81390.69321690981
2018-08-28T22:57:19.949Z 10676.179320626132
2018-08-28T22:57:19.949Z 10676.179320626132
我尝试使用外部查询中的GROUP BY time
语句来完成此操作,以使调用的周期与non_negative_derivative
相匹配。但是,当我尝试这样做时,我看到一个错误:
SELECT sum(d)
FROM (
SELECT non_negative_derivative(f64, 1m) as d
FROM _
WHERE __name__='rx_bytes' and dp_id='0x7'
GROUP BY port_name
)
GROUP BY time(1m)
ERR: aggregate function required inside the call to non_negative_derivative
这使我感到困惑,因为GROUP BY time
发生在内部查询之外,内部查询包含对non_negative_derivative
的调用。为什么外部GROUP BY
影响内部non_negative_derivative
?有办法解决这个问题吗?有没有更好的方法来解决此问题?
作为参考,这是基础数据的不太紧凑的视图。
SELECT non_negative_derivative(f64, 1m) as d
FROM _
WHERE __name__='rx_bytes' and dp_id='0x7'
GROUP BY port_name
LIMIT 5
name: _
tags: port_name=LOCAL
time d
---- -
2018-08-28T22:57:08.554Z 0
2018-08-28T22:57:09.586Z 0
2018-08-28T22:57:10.558Z 0
2018-08-28T22:57:19.949Z 0
2018-08-28T22:57:20.581Z 0
name: _
tags: port_name=s7-eth1
time d
---- -
2018-08-28T22:57:08.554Z 0
2018-08-28T22:57:09.586Z 0
2018-08-28T22:57:10.558Z 0
2018-08-28T22:57:19.949Z 10676.179320626132
2018-08-28T22:57:20.581Z 0
name: _
tags: port_name=s7-eth2
time d
---- -
2018-08-28T22:57:08.554Z 0
2018-08-28T22:57:09.586Z 0
2018-08-28T22:57:10.558Z 0
2018-08-28T22:57:19.949Z 10676.179320626132
2018-08-28T22:57:20.581Z 0
name: _
tags: port_name=s7-eth3
time d
---- -
2018-08-28T22:57:08.554Z 0
2018-08-28T22:57:09.586Z 12209.302325581395
2018-08-28T22:57:10.558Z 12962.962962962964
2018-08-28T22:57:19.949Z 81390.69321690981
2018-08-28T22:57:20.581Z 0