聚合函数sum()在influxdb中返回意外结果

时间:2019-04-01 13:38:09

标签: influxdb

influxdb中的sum()函数从子查询返回意外结果

子查询:

> select max(contador_total) - min(contador_total) as dif from _0_speed where time > now() - 30d group by cdv  

>name: _0_speed  
>tags: cdv=240AC415CD7C  
>time                dif  
>----                ---  
>1551532223396556745 11121  
>name: _0_speed  
>tags: cdv=240AC4166400  
>time                dif  
>----                ---  
>1551532223396556745 11190  

>name: _0_speed  
>tags: cdv=30AEA498FA10  
>time                dif  
>----                ---  
>1551532223396556745 33  
>name: _0_speed  
>tags: cdv=30AEA49B3188  
>time                dif  
>----                ---  
>1551532223396556745 5391859  

>name: _0_speed  
>tags: cdv=3C71BF1057DC  
>time                dif  
>----                ---  
>1551532223396556745 0  

具有sum()聚合的最终查询:

>select sum(dif) from (select max(contador_total) - min(contador_total) as dif from _0_speed where time > now() - 30d group by cdv)

>name: _0_speed  
>time sum  
>----                ---  
>0    11121  

预期结果:(11121 + 11190 + 33 + 5391859 + 0 = 5414203)

如果我尝试:

> select * from (select (max(contador_total) - min(contador_total)) as dif from _0_speed where time > now() - 30d group by cdv)  
>name: _0_speed  
>time                cdv          dif  
>----                ---          ---  
>1551531684580082568 240AC415CD7C 11121  
>1551531684580082568 30AEA498FA10   
>1551531684580082568 30AEA49B3188  
>1551531684580082568 30AEA498FA10  
>1551531684580082568 240AC4166400  
>1551531684580082568 3C71BF1057DC 0  
>1551531684580082568 240AC4166400  
>1551531684580082568 30AEA49B3188  

感谢您的帮助。

0 个答案:

没有答案