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

# maxMap

> maxMap 组合器使用示例

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

[`Map`](/zh/reference/functions/aggregate-functions/combinators#-map) 组合器可以应用于 [`max`](/zh/reference/functions/aggregate-functions/max)
函数，通过 `maxMap`
聚合组合器函数按每个键计算 Map 中的最大值。

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

在本示例中，我们将创建一个表，用于存储不同时间段的状态码及其计数，
其中每一行都包含一个从状态码映射到对应计数的 Map。我们将使用
`maxMap` 找出每个时间段内各状态码的最大计数。

```sql title="Query" theme={null}
CREATE TABLE metrics(
    date Date,
    timeslot DateTime,
    status Map(String, UInt64)
) ENGINE = MergeTree
ORDER BY ();

INSERT INTO metrics VALUES
    ('2000-01-01', '2000-01-01 00:00:00', (['a', 'b', 'c'], [15, 25, 35])),
    ('2000-01-01', '2000-01-01 00:00:00', (['c', 'd', 'e'], [45, 55, 65])),
    ('2000-01-01', '2000-01-01 00:01:00', (['d', 'e', 'f'], [75, 85, 95])),
    ('2000-01-01', '2000-01-01 00:01:00', (['f', 'g', 'g'], [105, 115, 125]));

SELECT
    timeslot,
    maxMap(status),
FROM metrics
GROUP BY timeslot;
```

`maxMap` 函数会找出每个时间槽中各状态码的最大计数。例如：

* 在时间槽 '2000-01-01 00:00:00' 中：
  * 状态 'a'：15
  * 状态 'b'：25
  * 状态 'c'：max(35, 45) = 45
  * 状态 'd'：55
  * 状态 'e'：65
* 在时间槽 '2000-01-01 00:01:00' 中：
  * 状态 'd'：75
  * 状态 'e'：85
  * 状态 'f'：max(95, 105) = 105
  * 状态 'g'：max(115, 125) = 125

```response title="Response" theme={null}
   ┌────────────timeslot─┬─maxMap(status)───────────────────────┐
1. │ 2000-01-01 00:01:00 │ {'d':75,'e':85,'f':105,'g':125}      │
2. │ 2000-01-01 00:00:00 │ {'a':15,'b':25,'c':45,'d':55,'e':65} │
   └─────────────────────┴──────────────────────────────────────┘
```

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

* [`max`](/zh/reference/functions/aggregate-functions/max)
* [`Map 组合器`](/zh/reference/functions/aggregate-functions/combinators#-map)
