Select Last From Different Tag

Hi,
Currently i have a table like this:
Time ID VAL
16:00:00 500856 5
16:00:30 500856 10
16:01:00 500856 15
16:01:30 500951 65
16:02:00 500951 100
16:02:30 507776 7

How can I get a higher value of each ID? I need to show something like this:
Time ID VAL
16:01:00 500856 15
16:02:00 500951 100
16:02:30 507776 7

Hello @joao25,
Welcome!
I’m assuming you’re using 2.x and Flux.
I find this table to be kinda confusing. You don’t get this result from InfluxDB unless you a) use a pivot or b) both ID and VAL are tags (which is surprising) and you’ve grouped your data together. Normally field keys and field values are separated out into two different columns.

Either way you’d do something like:

// whatever query you're using to get your data
//from(bucket: "<my bucket>")
//  |> range(start: <start time>, stop: <stop time>)
//  |> filter(fn: (r) => r["_measurement"] == "<my meausrement>")
//  |> filter(fn: (r) => r["_field"] == "VAL")
// Also is your ID a tag or a field? If it's a tag you won't need the first group(). Tags
  |> group(columns: ["ID"])
  |> max(column:"VAL") 
  |> group() 
  |> yield(name: "max VAL per ID")

I hope that helps!