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

> 引数の値をサンプリングして配列を作成します。生成される配列のサイズは `max_size` 要素までに制限されます。引数の値はランダムに選択されて配列に追加されます。

# groupArraySample

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

導入バージョン: v20.3.0

引数値のサンプルからなる配列を作成します。
生成される配列のサイズは `max_size` 要素に制限されます。
引数値はランダムに選択され、配列に追加されます。

**構文**

```sql theme={null}
groupArraySample(max_size[, seed])(x)
```

**パラメータ**

* `max_size` — 結果の配列の最大サイズ。[`UInt64`](/ja/reference/data-types/int-uint)
* `seed` — 任意。乱数ジェネレータのシード。デフォルト値: 123456。[`UInt64`](/ja/reference/data-types/int-uint)
* `x` — 引数 (カラム名または式) 。[`Any`](/ja/reference/data-types)

**引数**

* `array_column` — 集約対象の配列を含むカラム。[`Array`](/ja/reference/data-types/array)

**戻り値**

ランダムに選択された `x` 引数の配列。[`Array(T)`](/ja/reference/data-types/array)

**例**

**使用例**

```sql title=Query theme={null}
CREATE TABLE default.colors (
    id Int32,
    color String
) ENGINE = Memory;

INSERT INTO default.colors VALUES
(1, 'red'),
(2, 'blue'),
(3, 'green'),
(4, 'white'),
(5, 'orange');

SELECT groupArraySample(3)(color) as newcolors FROM default.colors;
```

```response title=Response theme={null}
┌─newcolors──────────────────┐
│ ['white','blue','green']   │
└────────────────────────────┘
```

**シードを使用する例**

```sql title=Query theme={null}
-- カラム名と異なるseedを使用したクエリ
SELECT groupArraySample(3, 987654321)(color) as newcolors FROM default.colors;
```

```response title=Response theme={null}
┌─newcolors──────────────────┐
│ ['red','orange','green']   │
└────────────────────────────┘
```

**引数として式を使用する**

```sql title=Query theme={null}
-- 引数として式を使用したクエリ
SELECT groupArraySample(3)(concat('light-', color)) as newcolors FROM default.colors;
```

```response title=Response theme={null}
┌─newcolors───────────────────────────────────┐
│ ['light-blue','light-orange','light-green'] │
└─────────────────────────────────────────────┘
```
