Search code examples
nosqlinfluxdb

Add negative condition in InfluxDB: AND NOT (meter_id='500' AND conso_prod='Prod')


I have this query in Influx 1.7

SELECT sum(delta) from measures  
WHERE operation_id='A1' 
AND time>'2020-05-19T22:00:00.000Z' AND time<'2020-05-26T22:00:00.000Z'  GROUP BY time(1d)

I want to exclude the results when (meter_id='500' AND conso_prod='Prod')

So, I tried to add:

AND NOT (meter_id='500' AND conso_prod='Prod')

but it seems NOT is not supported by influx.

So, I tried to write the negative, but it seems XOR doesn't exists neither.

It seems easy, but I can't do it. Any idea how should I do ?


Solution

  • Update your Where clause as follow:

    SELECT sum(delta) from measures  
    WHERE operation_id='A1' 
    AND time>'2020-05-19T22:00:00.000Z' AND time<'2020-05-26T22:00:00.000Z'  
    
    AND ( (meter_id='500' AND conso_prod!='Prod') OR (meter_id!='500' AND conso_prod='Prod') )
    
    GROUP BY time(1d)