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

Each aggregate function below covers **syntax** including parameters to pass to the function, and **examples** of how to use the function. Examples use NOAA water sample data.

## COUNT()

Returns the number of non-null field values. Supports all field value data types.

### Syntax

```
SELECT COUNT( [ * | <field_key> | /<regular_expression>/ ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause]
```

`COUNT(*)`

Returns the number of field values associated with each field key in the measurement.

`COUNT(field_key)`

Returns the number of field values associated with the field key.

`COUNT(/regular_expression/)`

Returns the number of field values associated with each field key that matches the regular expression.

#### Examples

## DISTINCT()

Returns the list of unique field values. Supports all field value data types.

InfluxQL supports nesting `DISTINCT()`

with `COUNT()`

.

### Syntax

```
SELECT DISTINCT( [ <field_key> | /<regular_expression>/ ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause]
```

`DISTINCT(field_key)`

Returns the unique field values associated with the field key.

#### Examples

## INTEGRAL()

Returns the area under the curve for subsequent field values.

`INTEGRAL()`

does not support `fill()`

. `INTEGRAL()`

supports int64 and float64 field value data types.

### Syntax

```
SELECT INTEGRAL( [ * | <field_key> | /<regular_expression>/ ] [ , <unit> ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause]
```

InfluxDB calculates the area under the curve for subsequent field values and converts those results into the summed area per `unit`

.
The `unit`

argument is an integer followed by an optional duration literal.
If the query does not specify the `unit`

, the unit defaults to one second (`1s`

).

`INTEGRAL(field_key)`

Returns the area under the curve for subsequent field values associated with the field key.

`INTEGRAL(/regular_expression/)`

Returns the area under the curve for subsequent field values associated with each field key that matches the regular expression.

`INTEGRAL(*)`

Returns the average field value associated with each field key in the measurement.

#### Examples

The following examples use a subset of the NOAA water sample data data:

```
SELECT "water_level" FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z'
```

time | water_level |
---|---|

2019-08-18T00:00:00Z | 2.3520000000 |

2019-08-18T00:06:00Z | 2.3790000000 |

2019-08-18T00:12:00Z | 2.3430000000 |

2019-08-18T00:18:00Z | 2.3290000000 |

2019-08-18T00:24:00Z | 2.2640000000 |

2019-08-18T00:30:00Z | 2.2670000000 |

## MEAN()

Returns the arithmetic mean (average) of field values. `MEAN()`

supports int64 and float64 field value data types.

### Syntax

```
SELECT MEAN( [ * | <field_key> | /<regular_expression>/ ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause]
```

`MEAN(field_key)`

Returns the average field value associated with the field key.

`MEAN(/regular_expression/)

Returns the average field value associated with each field key that matches the regular expression.

`MEAN(*)`

Returns the average field value associated with each field key in the measurement.

#### Examples

## MEDIAN()

Returns the middle value from a sorted list of field values. `MEDIAN()`

supports int64 and float64 field value data types.

**Note:** `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.

### Syntax

```
SELECT MEDIAN( [ * | <field_key> | /<regular_expression>/ ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause]
```

`MEDIAN(field_key)`

Returns the middle field value associated with the field key.

`MEDIAN(/regular_expression/)`

Returns the middle field value associated with each field key that matches the regular expression.

`MEDIAN(*)`

Returns the middle field value associated with each field key in the measurement.

#### Examples

## MODE()

Returns the most frequent value in a list of field values. `MODE()`

supports all field value data types.

**Note:** `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.

### Syntax

```
SELECT MODE( [ * | <field_key> | /<regular_expression>/ ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause]
```

`MODE(field_key)`

Returns the most frequent field value associated with the field key.

`MODE(/regular_expression/)`

Returns the most frequent field value associated with each field key that matches the regular expression.

`MODE(*)`

Returns the most frequent field value associated with each field key in the measurement.

#### Examples

## SPREAD()

Returns the difference between the minimum and maximum field values. `SPREAD()`

supports int64 and float64 field value data types.

### Syntax

```
SELECT SPREAD( [ * | <field_key> | /<regular_expression>/ ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause]
```

`SPREAD(field_key)`

Returns the difference between the minimum and maximum field values associated with the field key.

`SPREAD(/regular_expression/)`

Returns the difference between the minimum and maximum field values associated with each field key that matches the regular expression.

`SPREAD(*)`

Returns the difference between the minimum and maximum field values associated with each field key in the measurement.

#### Examples

## STDDEV()

Returns the standard deviation of field values. `STDDEV()`

supports int64 and float64 field value data types.

### Syntax

```
SELECT STDDEV( [ * | <field_key> | /<regular_expression>/ ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause]
```

`STDDEV(field_key)`

Returns the standard deviation of field values associated with the field key.

`STDDEV(/regular_expression/)`

Returns the standard deviation of field values associated with each field key that matches the regular expression.

`STDDEV(*)`

Returns the standard deviation of field values associated with each field key in the measurement.

#### Examples

## SUM()

Returns the sum of field values. `SUM()`

supports int64 and float64 field value data types.

### Syntax

```
SELECT SUM( [ * | <field_key> | /<regular_expression>/ ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause]
```

`SUM(field_key)`

Returns the sum of field values associated with the field key.

`SUM(/regular_expression/)`

Returns the sum of field values associated with each field key that matches the regular expression.

`SUM(*)`

Returns the sums of field values associated with each field key in the measurement.

#### Examples

Was this page helpful?

Thank you for your feedback!

#### Support and feedback

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 Cloud and InfluxDB Enterprise customers** can contact InfluxData Support.