Skip to main content
Since 0.0.11-beta The last aggregate allows you to get the value of one column as ordered by another. For example, last(temperature, time) returns the latest temperature value based on time within an aggregate group.
The last and first commands do not use indexes, they perform a sequential scan through the group. They are primarily used for ordered selection within a GROUP BY aggregate, and not as an alternative to an ORDER BY time DESC LIMIT 1 clause to find the latest value, which uses indexes.

Samples

Get the temperature every 5 minutes for each device over the past day:
This example uses first and last with an aggregate filter, and avoids null values in the output:

Arguments

The syntax is:

Returns