Search code examples
influxdb

Why sum and count give me unexpected results while using influxdb v.013


I'm not able to figure out how sum and count works. I'm using influxdb with version 0.13.

Let's say I've a time measurement with lots of data and first let me query it to get 10 rows:

> select count from X where time > 1472807400000000000 LIMIT 10

will respond with:

name: (X)
-------------------------
time                    count
1472807580000000000     1
1472807640000000000     1
1472807640000000000     1
1472807650000000000     3
1472807660000000000     1
1472807660000000000     6
1472807670000000000     1
1472807670000000000     3
1472807680000000000     1
1472807680000000000     1

Now I will sum this column:

> select sum(count) from X where time > 1472807400000000000 LIMIT 10

name: X
-------------------------
time                    sum
1472807400000000001     102

and count this column:

> select count(count) from X where time > 1472807400000000000 LIMIT 10

name: X
-------------------------
time                    count
1472807400000000001     44

What I was expecting

"count - Returns the number of non-null values in a single field" shouldn't that be 10 ?

"sum - Returns the sum of the all values in a single field." shouldn't that be value close to 19 ?(1,1,1,3,1,6,1,3,1,1)


Solution

  • The LIMIT clause limits the number of results that are returned. Any function call takes precedence.

    So

    select sum(count)  from X where time > 1472807400000000000 LIMIT 10
    

    is functionally equivalent to

    select sum(count)  from X where time > 1472807400000000000
    

    Similarly

    select count(count)  from X where time > 1472807400000000000 LIMIT 10
    

    is functionally equivalent to

    select count(count)  from X where time > 1472807400000000000