Influxdb: Addition of 2 fields doesn't work

Viewed 26

I have an influxdb with 2 fields i want to add and then find the max. I want so use an subquery for the addition of the two fields, but it doesn't work. Tried this:

Select "Field1" + "Field2" as Sum from "testTable" Order by time Desc Limit 10;

But the Sum is empty. Further i only print the fieldson the same way:

Select "Field1","Field2" from "testTable" Order by time Desc Limit 10;

Thats the result:

Result

enter image description here

Where I am doing the mistakes?

1 Answers

This might be easier to do in Flux:

import "influxdata/influxdb/schema"

from(bucket: "yourBucket")
  |> filter(fn: (r) => r["_measurement"] == "testTable")
  |> filter(fn: (r) => r["_field"] == "Field1" or r["_field"] == "Field2")
  |> schema.fieldsAsCols()
  |> map(fn: (r) => ({ r with Sum: r.Field1 + r.Field2 }))
  |> max(column: "Sum")
Related