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.
Some InfluxQL functions are in the process of being rearchitected to work with
the InfluxDB v3 storage engine. If a function you need is not here, check the
InfluxQL feature support page
for more information.
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
SELECTCOUNT(temp)FROMhome
name: home
time
count
1970-01-01T00:00:00Z
26
Count the number of non-null values in each field
SELECTCOUNT(*)FROMhome
name: home
time
count_co
count_hum
count_temp
1970-01-01T00:00:00Z
26
26
26
Count the number of non-null values in fields where the field key matches a regular expression
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
SELECTDISTINCT(co)FROMhome
name: home
time
distinct
1970-01-01T00:00:00Z
0
1970-01-01T00:00:00Z
1
1970-01-01T00:00:00Z
3
1970-01-01T00:00:00Z
4
1970-01-01T00:00:00Z
7
1970-01-01T00:00:00Z
5
1970-01-01T00:00:00Z
9
1970-01-01T00:00:00Z
18
1970-01-01T00:00:00Z
14
1970-01-01T00:00:00Z
22
1970-01-01T00:00:00Z
17
1970-01-01T00:00:00Z
26
MEAN()
Returns the arithmetic mean (average) of field values.
MEAN(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.
Examples
Calculate the mean value of a field
SELECTMEAN(temp)FROMhome
name: home
time
mean
1970-01-01T00:00:00Z
22.396153846153844
Calculate the mean value of each field
SELECTMEAN(*)FROMhome
name: home
time
mean_co
mean_hum
mean_temp
1970-01-01T00:00:00Z
5.269230769230769
36.15
22.396153846153844
Calculate the mean value of fields where the field key matches a regular expression
SELECTMEAN(/^[th]/)FROMhome
name: home
time
mean_hum
mean_temp
1970-01-01T00:00:00Z
36.15
22.396153846153844
Calculate the mean value of a field within time windows (grouped by time)
Returns the middle value from a sorted list of field values.
MEDIAN(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
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
SELECTMEDIAN(temp)FROMhome
name: home
time
median
1970-01-01T00:00:00Z
22.45
Calculate the median value of each field
SELECTMEDIAN(*)FROMhome
name: home
time
median_co
median_hum
median_temp
1970-01-01T00:00:00Z
1
36.05
22.45
Calculate the median value of fields where the field key matches a regular expression
SELECTMEDIAN(/^[th]/)FROMhome
name: home
time
median_hum
median_temp
1970-01-01T00:00:00Z
36.05
22.45
Calculate the median value of a field within time windows (grouped by time)
Returns the most frequent value in a list of
field values.
MODE(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 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
SELECTMODE(co)FROMhome
name: home
time
mode
1970-01-01T00:00:00Z
0
Calculate the mode value of each field
SELECTMODE(*)FROMhome
name: home
time
mode_co
mode_hum
mode_temp
1970-01-01T00:00:00Z
0
36
22.7
Calculate the mode of field keys that match a regular expression
SELECTMODE(/^[th]/)FROMhome
name: home
time
mode_hum
mode_temp
1970-01-01T00:00:00Z
36
22.7
Calculate the mode a field within time windows (grouped by time)
Returns the difference between the minimum and maximum
field values.
SPREAD(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.
Examples
Calculate the spread of a field
SELECTSPREAD(temp)FROMhome
name: home
time
spread
1970-01-01T00:00:00Z
2.3000000000000007
Calculate the spread of each field
SELECTSPREAD(*)FROMhome
name: home
time
spread_co
spread_hum
spread_temp
1970-01-01T00:00:00Z
26
1
2.3000000000000007
Calculate the spread of field keys that match a regular expression
SELECTSPREAD(/^[th]/)FROMhome
name: home
time
spread_hum
spread_temp
1970-01-01T00:00:00Z
1
2.3000000000000007
Calculate the spread of a field within time windows (grouped by time)
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
SELECTSTDDEV(temp)FROMhome
name: home
time
stddev
1970-01-01T00:00:00Z
0.5553238833191091
Calculate the standard deviation of each field
SELECTSTDDEV(*)FROMhome
name: home
time
stddev_co
stddev_hum
stddev_temp
1970-01-01T00:00:00Z
7.774613519951676
0.25495097567963926
0.5553238833191091
Calculate the standard deviation of fields where the field key matches a regular expression
SELECTSTDDEV(/^[th]/)FROMhome
name: home
time
stddev_hum
stddev_temp
1970-01-01T00:00:00Z
0.25495097567963926
0.5553238833191091
Calculate the standard deviation of a field within time windows (grouped by time)
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
SELECTSUM(co)FROMhome
name: home
time
sum
1970-01-01T00:00:00Z
137
Calculate the sum of values in each field
SELECTSUM(*)FROMhome
name: home
time
sum_co
sum_hum
sum_temp
1970-01-01T00:00:00Z
137
939.9
582.3
Calculate the sum of values for fields where the field key matches a regular expression
SELECTSUM(/^[th]/)FROMhome
name: home
time
sum_hum
sum_temp
1970-01-01T00:00:00Z
939.9
582.3
Calculate the sum of values in a field within time windows (grouped by time)
Thank you for being part of our community!
We welcome and encourage your feedback and bug reports for InfluxDB and this documentation.
To find support, use the following resources:
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.
You are currently viewing documentation specific to InfluxDB Cloud
Serverless
powered by the v3 storage engine, which
offers different functionality than InfluxDB Cloud
powered by the TSM storage engine.