InfluxDB - Getting only last value in query

SELECT last(value) FROM response_times WHERE time > now() - 1h;

That should return the last value of the column.

However, if you want you can split up the sequence in smaller pieces and select the last value. For instance:

 SELECT last(value) FROM response_times WHERE time > now() - 1h GROUP BY time(60s);

It will split up the sequence in 60-second fragments and will pick up for each fragment the latest value.


In the API, have a look at first/last to select the first or last record of a column. You also have top/bottom to select more than one record

[edit] top/bottom seem to return higest/lowest values of the time frame


If you are using InfluxDB 0.8 dont use FIRST() or LAST() if you have not GROUP BY because its very slow :(

So if you want to get the these Values you shoud use:

First Value:

SELECT * FROM <SERIES> GROUP BY * ORDER BY ASC LIMIT 1

Last Value:

SELECT * FROM <SERIES> GROUP BY * ORDER BY DESC LIMIT 1

Don't delete the GROUP BY * because then it could be possible that you get unexpected values then.

Tags:

Influxdb