Documentation

InfluxQL aggregate functions

Use aggregate functions to assess, aggregate, and return values in your data. Aggregate functions return one row containing the aggregate 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 storage engine. If a function you need is not here, check the InfluxQL feature support page for more information.

COUNT()

Returns the number of non-null field values.

COUNT(field_expression)
  • Copy
  • Fill window

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 types.

Examples

Count the number of non-null values in a field

Count the number of non-null values in each field

Count the number of non-null values in fields where the field key matches a regular expression

Count distinct values for a field

Count the number of non-null field values within time windows (grouped by time)

DISTINCT()

Returns the list of unique field values.

DISTINCT(field_key)
  • Copy
  • Fill window

Arguments

  • field_key: Field key to return distinct values from. Supports all field types.

Notable behaviors

  • InfluxQL supports nesting DISTINCT() with COUNT().

Examples

List the distinct field values

MEAN()

Returns the arithmetic mean (average) of field values.

MEAN(field_expression)
  • Copy
  • Fill window

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.

Examples

Calculate the mean value of a field

Calculate the mean value of each field

Calculate the mean value of fields where the field key matches a regular expression

Calculate the mean value of a field within time windows (grouped by time)

MEDIAN()

Returns the middle value from a sorted list of field values.

MEDIAN(field_expression)
  • Copy
  • Fill window

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

  • MEDIAN() is nearly equivalent to PERCENTILE(field_key, 50), except MEDIAN() returns the average of the two middle field values if the field contains an even number of values.

Examples

Calculate the median value of a field

Calculate the median value of each field

Calculate the median value of fields where the field key matches a regular expression

Calculate the median value of a field within time windows (grouped by time)

MODE()

Returns the most frequent value in a list of field values.

MODE(field_expression)
  • Copy
  • Fill window

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 types.

Notable behaviors

  • MODE() returns the field value with the earliest timestamp if there’s a tie between two or more values for the maximum number of occurrences.

Examples

Calculate the mode value of a field

Calculate the mode value of each field

Calculate the mode of field keys that match a regular expression

Calculate the mode a field within time windows (grouped by time)

SPREAD()

Returns the difference between the minimum and maximum field values.

SPREAD(field_expression)
  • Copy
  • Fill window

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.

Examples

Calculate the spread of a field

Calculate the spread of each field

Calculate the spread of field keys that match a regular expression

Calculate the spread of a field within time windows (grouped by time)

STDDEV()

Returns the standard deviation of field values.

STDDEV(field_expression)
  • Copy
  • Fill window

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.

Examples

Calculate the standard deviation of a field

Calculate the standard deviation of each field

Calculate the standard deviation of fields where the field key matches a regular expression

Calculate the standard deviation of a field within time windows (grouped by time)

SUM()

Returns the sum of field values.

SUM(field_expression)
  • Copy
  • Fill window

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.

Examples

Calculate the sum of values in a field

Calculate the sum of values in each field

Calculate the sum of values for fields where the field key matches a regular expression

Calculate the sum of values in a field within time windows (grouped by time)


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 3 Core and Enterprise are now in Beta

InfluxDB 3 Core and Enterprise are now available for beta testing, available under MIT or Apache 2 license.

InfluxDB 3 Core is a high-speed, recent-data engine that collects and processes data in real-time, while persisting it to local disk or object storage. InfluxDB 3 Enterprise is a commercial product that builds on Core’s foundation, adding high availability, read replicas, enhanced security, and data compaction for faster queries. A free tier of InfluxDB 3 Enterprise will also be available for at-home, non-commercial use for hobbyists to get the full historical time series database set of capabilities.

For more information, check out: