> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-3a82795f.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`](/zh/reference/data-types/int-uint)
* `seed` — 可选。随机数生成器的种子。默认值：123456。[`UInt64`](/zh/reference/data-types/int-uint)
* `x` — 参数 (列名或表达式) 。[`Any`](/zh/reference/data-types)

**Arguments**

* `array_column` — 包含待聚合数组的列。[`Array`](/zh/reference/data-types/array)

**返回值**

由随机选取的 `x` 值组成的数组。[`Array(T)`](/zh/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}
-- 使用列名和不同种子值的查询
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'] │
└─────────────────────────────────────────────┘
```
