Documentation

InfluxQL selector functions

Limited availability

InfluxDB Clustered is currently only available to a limited group of InfluxData customers. If interested in being part of the limited access group, please contact the InfluxData Sales team.

Use selector functions to assess, select, and return values in your data. Selector functions return one or more rows with the selected values from each InfluxQL group.

Examples use the sample data set provided in the Get started with InfluxDB tutorial.

Missing InfluxQL functions

Some InfluxQL functions are in the process of being rearchitected to work with the InfluxDB 3.0 storage engine. If a function you need is not here, check the InfluxQL feature support page for more information.

BOTTOM()

Returns the smallest N field values. BOTTOM() supports int64 and float64 field value data types.

BOTTOM(field_expression[, tag_expression_1[, ..., tag_expression_n]], N)

Note: BOTTOM() returns the field value with the earliest timestamp if there’s a tie between two or more values for the smallest value.

Arguments

  • field_expression: Expression to identify the field to operate on. Can be a field key or constant.
  • tag_expression: Expression to identify a tag key to segment by. Can be a tag key or constant. Comma-delimit multiple tags.
  • N: Number of results to return from each InfluxQL group or specified tag segment.

Notable behaviors

Examples

Select the bottom three values of a field

Select the bottom field value for two unique tag values

Select the bottom three field values and the tag value associated with each

Select the bottom field values for unique tag values and within time windows (grouped by time)

FIRST()

Returns the field value with the oldest timestamp.

FIRST(field_expression)

Arguments

  • field_expression: Expression to identify one or more fields to operate on. Can be a field key, constant, regular expression, or wildcard (*). Supports all field data types.

Notable behaviors

Examples

Select the first value for a field

Select the first value from each field

Select the first value from field keys that match a regular expression

Select the first value from a field within time windows (grouped by time)

LAST()

Returns the field value with the most recent timestamp.

LAST(field_expression)

Arguments

  • field_expression: Expression to identify one or more fields to operate on. Can be a field key, constant, regular expression, or wildcard (*). Supports all field data types.

Notable behaviors

Examples

Select the last value for a field

Select the last value from each field

Select the last value from field keys that match a regular expression

Select the last value from a field within time windows (grouped by time)

MAX()

Returns the greatest field value.

MAX(field_expression)

Arguments

  • field_expression: Expression to identify one or more fields to operate on. Can be a field key, constant, regular expression, or wildcard (*). Supports numeric fields.

Notable behaviors

Examples

Select the maximum value from a field

Select the maximum value from each field

Select the maximum value from field keys that match a regular expression

Select the maximum value from a field within time windows (grouped by time)

MIN()

Returns the lowest field value.

MIN(field_expression)

Arguments

  • field_expression: Expression to identify one or more fields to operate on. Can be a field key, constant, regular expression, or wildcard (*). Supports numeric fields.

Notable behaviors

Examples

Select the minimum value from a field

Select the minimum value from each field

Select the minimum value from field keys that match a regular expression

Select the minimum value from a field within time windows (grouped by time)

PERCENTILE()

Returns the Nth percentile field value.

PERCENTILE(field_expression, N)

Arguments

  • field_expression: Expression to identify one or more fields to operate on. Can be a field key, constant, regular expression, or wildcard (*). Supports numeric fields.
  • N: Percentile to return. Must be an integer or float value greater than 0 and less than or equal to 100.

Notable behaviors

Examples

Select the 50th percentile value from a field

Select the 50th percentile value from each field

Select the 50th percentile value from field keys that match a regular expression

Select the 50th percentile value from a field within time windows (grouped by time)

TOP()

Returns the greatest N field values. TOP() supports int64 and float64 field value data types.

TOP(field_expression[, tag_expression_1[, ..., tag_expression_n]], N)

Note: TOP() returns the field value with the earliest timestamp if there’s a tie between two or more values for the greatest value.

Arguments

  • field_expression: Expression to identify the field to operate on. Can be a field key or constant.
  • tag_expression: Expression to identify a tag key to segment by. Can be a tag key or constant. Comma-delimit multiple tags.
  • N: Number of results to return from each InfluxQL group or specified tag segment.

Notable behaviors

Examples

Select the top three values of a field

Select the top field value for two unique tag values

Select the top three field values and the tag value associated with each

Select the top field values for unique tag values and within time windows (grouped by time)

Notable behaviors of selector functions

Timestamps when grouping by time

When using selector functions with a GROUP BY time() clause, most selector functions return the timestamp of the starting boundary for each time interval. However functions with an N argument that specifies the number of results to return per group maintain the original timestamp of each returned point.

Return the start time of each time interval
Maintain the original timestamp

Selector functions may return fewer points than expected

Queries that use the following selector functions with an N argument may return fewer points than expected.

If the InfluxQL group or specified tag key contains X points or unique tag values and X is less than N, the function returns X results instead of N for each group or tag value.

View example for FN(field_key, N)

View example for FN(field_key, tag_key, N)


Was this page helpful?

Thank you for your feedback!


The future of Flux

Flux is going into maintenance mode. You can continue using it as you currently are without any changes to your code.

Flux is going into maintenance mode and will not be supported in InfluxDB 3.0. This was a decision based on the broad demand for SQL and the continued growth and adoption of InfluxQL. We are continuing to support Flux for users in 1.x and 2.x so you can continue using it with no changes to your code. If you are interested in transitioning to InfluxDB 3.0 and want to future-proof your code, we suggest using InfluxQL.

For information about the future of Flux, see the following: