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

# groupArrayResample

> groupArray 使用 Resample 组合器的示例

<div id="description">
  ## 说明
</div>

[`Resample`](/zh/reference/functions/aggregate-functions/combinators#-resample)
组合器可应用于 [`groupArray`](/zh/reference/functions/aggregate-functions/sum) 聚合函数，用于
将指定键列的范围划分为固定数量的区间 (`N`) ，
并通过从落入每个区间的数据点中选取一个代表值
(对应最小键) 来构造结果数组。
它生成的是数据的降采样视图，而不是收集所有值。

<div id="example-usage">
  ## 示例用法
</div>

来看一个示例。我们将创建一个包含员工 `name`、`age` 和
`wage` 的表，并向其中插入一些数据：

```sql theme={null}
CREATE TABLE employee_data 
(
    name String,
    age UInt8,
    wage Float32
) ENGINE = MergeTree()
ORDER BY tuple()

INSERT INTO employee_data (name, age, wage) VALUES
    ('John', 16, 10.0),
    ('Alice', 30, 15.0),
    ('Mary', 35, 8.0),
    ('Evelyn', 48, 11.5),
    ('David', 62, 9.9),
    ('Brian', 60, 16.0);
```

让我们获取年龄落在 `[30,60)` 和 `[60,75)` 区间内的人员姓名。
由于年龄使用整数表示，因此对应的年龄会落在
`[30, 59]` 和 `[60,74]` 区间内。

要将姓名聚合到数组中，我们使用 `groupArray` 聚合函数。
它接受一个参数。在本例中，这个参数就是姓名列。`groupArrayResample`
函数应使用年龄列按年龄聚合姓名。为了定义所需的
区间，我们将 `30`、`75`、`30` 作为参数传递给 `groupArrayResample`
函数：

```sql theme={null}
SELECT groupArrayResample(30, 75, 30)(name, age) FROM employee_data
```

```response theme={null}
┌─groupArrayResample(30, 75, 30)(name, age)─────┐
│ [['Alice','Mary','Evelyn'],['David','Brian']] │
└───────────────────────────────────────────────┘
```

<div id="see-also">
  ## 另见
</div>

* [`groupArray`](/zh/reference/functions/aggregate-functions/groupArray)
* [`Resample 组合器`](/zh/reference/functions/aggregate-functions/combinators#-resample)
