How to get a simple max() function

Hi.

I have a query (which comes from Grafana):

SELECT sum(“c”) FROM “mqtt_consumer” WHERE (“topic” = ‘PBX/Live’) AND time >= now() - 1h

So far, so good. However, I wish to ensure that the lowest value of this query is zero (ie: never negative, which is sometimes possible given the data in the table).

Therefore I want to do something like:

SELECT max(0,sum(“c”)) FROM “mqtt_consumer” WHERE (“topic” = ‘PBX/Live’) AND time >= now() - 1h

except that the max() function doesn’t work like that - it expects a single parameter which is a field key.

Any idea how I can achieve this in Influx?

Antony.

Hi ,

is this a good alternative ?

SELECT sum(“c”) FROM “mqtt_consumer” WHERE (“topic” = ‘PBX/Live’) AND time >= now() - 1h and “c” > 0

No, because the individual values of c may be positive or negative. It’s only
the sum that it makes sense to limit to >=0 only.

Antony.