InfluxDB mixing agregation function with non-aggregat fields/values

3.8k views Asked by At

I have a following issue: I need to calculate difference between consecutive points where some arbitrary ID is equal. The following:

SELECT difference(value_field) FROM mesurementName WHERE "IdField" = '10'

Works, returns difference between each consecutive point with IdField BUT IdField is lost (only time is propagated to query result). In my case time is not unique (i.e. measurement may contain many points with same timestamp, but different IdField). So I tried:

SELECT difference(value_field), IdField FROM mesurementName WHERE "IdField" = '10'

which yields: error parsing query: mixing aggregate and non-aggregate queries is not supported!!

My next attempt was using sub-query:

SELECT IdField, diff
FROM (
    SELECT 
        difference(flow_val) as diff
    FROM 
        mesurementA
    WHERE  "IdField" = '10' 
)

Which resulted in always null value in IdField.

I'd like to ask you for help or suggestion how to solve issue. By the way, we are using InfluxDB 1.3, which is not supporting JOIN anymore

1

There are 1 answers

0
Tomas On

If anyone would stuck as I was, then solution is following:

SELECT difference(value_field) FROM mesurementName GROUP BY "IdField"

Above somehow implicitly add "IdField" to result series and is propagated to resulting measurements with INTO clause