> ## Documentation Index
> Fetch the complete documentation index at: https://docs.firebolt.io/llms.txt
> Use this file to discover all available pages before exploring further.

> Reference material for AVG

# AVG

Calculates the average of an expression.

## Syntax

```sql theme={"theme":{"light":"css-variables","dark":"css-variables"}}
AVG(<value>) [FILTER ([WHERE] <condition>)]
```

## Parameters

| Parameter     | Description                                                       | Supported input types |
| :------------ | :---------------------------------------------------------------- | :-------------------- |
| `<value>`     | The expression used to calculate the average                      | Any numeric type      |
| `<condition>` | An optional boolean expression to filter rows used in aggregation | `BOOL`                |

Valid values for the expression include column names or functions that return a column name (or columns) that contain numeric values.

The `AVG()` aggregate function ignores rows with `NULL` values. For example, an `AVG` from 3 rows containing `1`, `2`, and `NULL` returns `1.5` because the `NULL` row is not counted. To calculate an average that includes `NULL`, use `SUM(COLUMN)/COUNT(*)`.

## Return Types

* `NUMERIC` if the input is type `INTEGER`, `BIGINT` or `NUMERIC`
* `DOUBLE PRECISION` if the input is type `REAL` or `DOUBLE PRECISION`

## Precision and Determinism

Applying `AVG` to REAL and DOUBLE PRECISION is subject to [floating point arithmetic accuracy limitations](https://en.wikipedia.org/wiki/Floating-point_arithmetic#Accuracy_problems) and its resulting error.
This error may add up when aggregating multiple values.

The order of operations while computing the aggregate is non-deterministic.
This can lead to varying total floating point error when running a query multiple times.
If this is not acceptable for your use-case, aggregate on [NUMERIC](/reference-sql/data-types/numeric) data instead.

## Example

The `levels` table contains the following values:

<div className="query-window">
  ```
  SELECT level, maxpoints FROM levels ORDER BY level;
  ```

  | level <span>int null</span> | maxpoints <span>int null</span> |
  | :-------------------------- | :------------------------------ |
  | 1                           | 20                              |
  | 2                           | 30                              |
  | 3                           | 40                              |
  | 4                           | 100                             |
  | 5                           | 150                             |
  | 6                           | 80                              |
  | 7                           | 70                              |
  | 8                           | 100                             |
  | 9                           | 250                             |
  | 10                          | 500                             |

  <p><span>Rows: 10</span><span>Execution time: 6.00ms</span></p>
</div>

The following example calculates the average `maxpoints` across all levels in the `levels` table:

<div className="query-window">
  ```
  SELECT AVG(maxpoints) AS averagemaxpoints FROM levels;
  ```

  | averagemaxpoints <span>double null</span> |
  | :---------------------------------------- |
  | 134                                       |

  <p><span>Rows: 1</span><span>Execution time: 8.82ms</span></p>
</div>
