潮流中的子选择计数没有返回任何东西

时间:2017-12-11 18:24:05

标签: influxdb

我有一些数据结构

select * from rules where time > now() - 1m limit 5

name: rules
time                ackrate consumers deliverrate hostname    publishrate ready redeliverrate shard unacked version
----                ------- --------- ----------- --------    ----------- ----- ------------- ----- ------- -------
1513012628943000000 864     350       861.6       se-rabbit14 975.8       0     0             14    66      5
1513012628943000000 864.8   350       863         se-rabbit9  920.8       0     0             09    64      5
1513012628943000000 859.8   350       860.2       se-rabbit8  964.2       0     0             08    58      5
1513012628943000000 864.8   350       863.6       se-rabbit16 965.4       0     0             16    64      5
1513012631388000000 859.8   350       860.2       se-rabbit8  964.2       0     0             08    58      5

我想计算'up-time'的百分比,定义为队列没有就绪消息的时间。

我可以在每分钟获得最大准备数

select max(ready) from rules where time > now() - 1h group by time(1m) limit 5

name: rules
time                max
----                ---
1513009560000000000 0
1513009620000000000 0
1513009680000000000 0
1513009740000000000 0
1513009800000000000 0

使用子查询,我只能选择已准备好值的分钟。

select ready from (select max(ready) as ready from rules where time > now() - 1h group by time(1m)) where ready > 0

name: rules
time                ready
----                -----
1513010520000000000 49
1513013280000000000 57

我想得到这些值的计数,然后做一些数学计算一个百分比。在这种情况下,最后一小时有2个结果,

<(>((60分钟* 1小时) - 2)/(60分钟* 1小时))== 96%

当我试图计算这个时,我没有得到回应。

select count(ready) from (select max(ready) as ready from rules where time > now() - 1h group by time(1m)) where ready > 0

这是v1.2.2。

如何返回结果数量?

1 个答案:

答案 0 :(得分:0)

解决方案只是从v1.2.2升级到v1.3.8。使用更高版本。

select count(ready) from (select max(ready) as ready from rules where time > now() - 1h group by time(1m)) where ready > 0
name: rules
time count
---- -----
0    6