Documentation

SQL aggregate functions

SQL aggregate functions aggregate values in a specified column for each group or SQL partition and return a single row per group containing the aggregate value.


General aggregate functions

avg

Returns the average of numeric values in the specified column.

avg(expression)
Arguments:
  • expression: Column to operate on.
Aliases:
  • mean

View avg query example

count

Returns the number of rows in the specified column.

Count includes null values in the total count. To exclude null values from the total count, include <column> IS NOT NULL in the WHERE clause.

count(expression)
Arguments:
  • expression: Column to operate on.

View count query example

max

Returns the maximum value in the specified column.

To return both the maximum value and its associated timestamp, use selector_max.

Arguments:
  • expression: Column to operate on.

View max query example

mean

Alias of avg.

min

Returns the minimum value in the specified column.

To return both the minimum value and its associated timestamp, use selector_max.

Arguments:
  • expression: Column to operate on.

View min query example

sum

Returns the sum of all values in the specified column.

Arguments:
  • expression: Column to operate on.

View sum query example

Statistical aggregate functions

corr

Returns the coefficient of correlation between two numeric values.

corr(expression1, expression2)
Arguments:
  • expression1: First column or literal value to operate on.
  • expression2: Second column or literal value to operate on.

View corr query example

covar

Returns the covariance of a set of number pairs.

covar(expression1, expression2)
Arguments:
  • expression1: First column or literal value to operate on.
  • expression2: Second column or literal value to operate on.

View covar query example

covar_pop

Returns the population covariance of a set of number pairs.

covar_pop(expression1, expression2)
Arguments:
  • expression1: First column or literal value to operate on.
  • expression2: Second column or literal value to operate on.

View covar_pop query example

covar_samp

Returns the sample covariance of a set of number pairs.

covar_samp(expression1, expression2)
Arguments:
  • expression1: First column or literal value to operate on.
  • expression2: Second column or literal value to operate on.

View covar_samp query example

stddev

Returns the standard deviation of a set of numbers.

stddev(expression)
Arguments:
  • expression: Column or literal value to operate on.

View stddev query example

stddev_pop

Returns the population standard deviation of a set of numbers.

stddev_pop(expression)
Arguments:
  • expression: Column or literal value to operate on.

View stddev_pop query example

stddev_samp

Returns the sample standard deviation of a set of numbers.

stddev_samp(expression)
Arguments:
  • expression: Column or literal value to operate on.

View stddev_samp query example


var

Returns the statistical variance of a set of numbers.

var(expression)
Arguments:
  • expression: Column or literal value to operate on.

View var query example

var_pop

Returns the statistical population variance of a set of numbers.

var_pop(expression)
Arguments:
  • expression: Column or literal value to operate on.

View var_pop query example

var_samp

Returns the statistical sample variance of a set of numbers.

var_samp(expression)
Arguments:
  • expression: Column or literal value to operate on.

View var_samp query example

Approximate aggregate functions

approx_distinct

Returns the approximate number of distinct input values calculated using the HyperLogLog algorithm.

approx_distinct(expression)
Arguments
  • expression: Column or literal value to operate on.

View approx_distinct query example

approx_median

Returns the approximate median (50th percentile) of input values. It is an alias of approx_percentile_cont(x, 0.5).

approx_median(expression)
Arguments
  • expression: Column or literal value to operate on.

View approx_median query example

approx_percentile_cont

Returns the approximate percentile of input values using the t-digest algorithm.

approx_percentile_cont(expression, percentile, centroids)
Arguments
  • expression: Column or literal value to operate on.

  • percentile: Percentile to compute. Must be a float value between 0 and 1 (inclusive).

  • centroids: Number of centroids to use in the t-digest algorithm. Default is 100.

    If there are this number or fewer unique values, you can expect an exact result. A higher number of centroids results in a more accurate approximation, but requires more memory to compute.

View approx_percentile_cont query example

approx_percentile_cont_with_weight

Returns the weighted approximate percentile of input values using the t-digest algorithm.

approx_percentile_cont_with_weight(expression, weight, percentile)
Arguments
  • expression: Column or literal value to operate on.
  • weight: Column or literal value to use as weight.
  • percentile: Percentile to compute. Must be a float value between 0 and 1 (inclusive).

View approx_percentile_cont_with_weight query example


Was this page helpful?

Thank you for your feedback!


Linux Package Signing Key Rotation

All signed InfluxData Linux packages have been resigned with an updated key. If using Linux, you may need to update your package configuration to continue to download and verify InfluxData software packages.

For more information, see the Linux Package Signing Key Rotation blog post.

InfluxDB Cloud backed by InfluxDB IOx

All InfluxDB Cloud organizations created on or after January 31, 2023 are backed by the new InfluxDB IOx storage engine. Check the right column of your InfluxDB Cloud organization homepage to see which InfluxDB storage engine you’re using.

If powered by IOx, this is the correct documentation.

If powered by TSM, see the TSM-based InfluxDB Cloud documentation.

InfluxDB Cloud backed by InfluxDB TSM

All InfluxDB Cloud organizations created on or after January 31, 2023 are backed by the new InfluxDB IOx storage engine which enables nearly unlimited series cardinality and SQL query support. Check the right column of your InfluxDB Cloud organization homepage to see which InfluxDB storage engine you’re using.

If powered by TSM, this is the correct documentation.

If powered by IOx, see the IOx-based InfluxDB Cloud documentation.

State of the InfluxDB Cloud (IOx) documentation

The new documentation for InfluxDB Cloud backed by InfluxDB IOx is a work in progress. We are adding new information and content almost daily. Thank you for your patience!

If there is specific information you’re looking for, please submit a documentation issue.