Query in Influxdb 2.0

Hello,
can you please help me with this.

influx v1.7 query:

SELECT max(“Ziehkraft_IST_LIN_int”) FROM “TESTING1” WHERE (“Drehzahl_Istwert_vom_Regler” < 0.725) GROUP BY “COIL_ID”

output :
name: TESTING1
tags: COIL_ID=1
time max


1502831736010000000 109

name: TESTING1
tags: COIL_ID=2
time max


1502832704780000000 101

name: TESTING1
tags: COIL_ID=3
time max


1502833824960000000 103

name: TESTING1
tags: COIL_ID=4
time max


1502834763850000000 105

name: TESTING1
tags: COIL_ID=5
time max


1502836417140000000 108

name: TESTING1
tags: COIL_ID=6
time max


1502837445090000000 103

I want to write this in influx 2.0 but not able to write the query:
I tried this:

from(bucket: “project”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: ( r ) =>
r._measurement == “machine” and
r._field =~ /Ziehkraft_IST_LIN_int|Drehzahl_Istwert_vom_Regler/
)
|>pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: “_value”)
|> filter(fn: ( r ) => r.Drehzahl_Istwert_vom_Regler < 0.725)
|> group(columns: [“coil_id”])
|>max( column:“Ziehkraft_IST_LIN_int”)

output:

but showing different result of Ziehkraft_IST_LIN_int value. Is there any mistake in using group by ?How to solve it. Please let me know.

This is the solution I found:

from(bucket: "test")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) =>
r._measurement == "test1" and
r._field =~ /Ziehkraft_IST_LIN_int|Drehzahl_Istwert_vom_Regler/
)
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
|> filter(fn: (r) => r.Drehzahl_Istwert_vom_Regler < 0.725)
|> group(columns: ["coil_id"])
|>max(column: "Ziehkraft_IST_LIN_int")
1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.