Documentation

InfluxQL selector functions

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.

Read more

InfluxDB v3 enhancements and InfluxDB Clustered is now generally available

New capabilities, including faster query performance and management tooling advance the InfluxDB v3 product line. InfluxDB Clustered is now generally available.

InfluxDB v3 performance and features

The InfluxDB v3 product line has seen significant enhancements in query performance and has made new management tooling available. These enhancements include an operational dashboard to monitor the health of your InfluxDB cluster, single sign-on (SSO) support in InfluxDB Cloud Dedicated, and new management APIs for tokens and databases.

Learn about the new v3 enhancements


InfluxDB Clustered general availability

InfluxDB Clustered is now generally available and gives you the power of InfluxDB v3 in your self-managed stack.

Talk to us about InfluxDB Clustered