Home > database >  How can I query last 10 data in Influxdb2.0
How can I query last 10 data in Influxdb2.0

Time:05-11

I tried to query the latest 10 of data, but I only saw from the official documentation how to query the latest 1 of data, has anyone tried it?

|> last()

CodePudding user response:

You need two functions:

  1. Use the sort function with the desc flag set to "true":

    |> sort(columns: ["_value"], desc: true)

  2. Then use the limit function to get only 10 rows of the output, which in your case are the 10 latest points since you sorted the output in descending order:

    |> limit(n: 10)

  • Related