> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-8a08bda2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> 算術平均を算出します。

# avg

<div id="avg">
  ## avg
</div>

導入バージョン: v1.1.0

算術平均を返します。

**構文**

```sql theme={null}
avg(x)
```

**引数**

* `x` — 入力値。[`(U)Int*`](/ja/reference/data-types/int-uint) または [`Float*`](/ja/reference/data-types/float) または [`Decimal`](/ja/reference/data-types/decimal)

**戻り値**

算術平均を返します。引数 `x` が空の場合は `NaN` を返します。[`Float64`](/ja/reference/data-types/float)

**例**

**基本的な使い方**

```sql title=Query theme={null}
SELECT avg(x) FROM VALUES('x Int8', 0, 1, 2, 3, 4, 5);
```

```response title=Response theme={null}
┌─avg(x)─┐
│    2.5 │
└────────┘
```

**空のテーブルでは NaN が返されます**

```sql title=Query theme={null}
CREATE TABLE test (t UInt8) ENGINE = Memory;

SELECT avg(t) FROM test;
```

```response title=Response theme={null}
┌─avg(x)─┐
│    nan │
└────────┘
```
