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

# sumMap

> sumMap コンビネータの使用例

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

[`Map`](/ja/reference/functions/aggregate-functions/combinators#-map) コンビネータは、[`sum`](/ja/reference/functions/aggregate-functions/sum)
関数に適用でき、`sumMap`
集約コンビネータ関数を使用して、Map 内の値の合計をキーごとに計算します。

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

この例では、時間帯ごとのステータスコードとその件数を格納するテーブルを作成します。
各行には、ステータスコードとそれに対応する件数を保持する Map が含まれます。各時間帯における
各ステータスコードの合計件数を計算するために、`sumMap` を使用します。

```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,
    sumMap(status),
FROM metrics
GROUP BY timeslot;
```

`sumMap` 関数は、各タイムスロット内の各ステータスコードごとの合計を計算します。たとえば、次のとおりです。

* タイムスロット '2000-01-01 00:00:00':
  * ステータス 'a': 15
  * ステータス 'b': 25
  * ステータス 'c': 35 + 45 = 80
  * ステータス 'd': 55
  * ステータス 'e': 65
* タイムスロット '2000-01-01 00:01:00':
  * ステータス 'd': 75
  * ステータス 'e': 85
  * ステータス 'f': 95 + 105 = 200
  * ステータス 'g': 115 + 125 = 240

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

<div id="see-also">
  ## 関連項目
</div>

* [`sum`](/ja/reference/functions/aggregate-functions/sum)
* [`Map コンビネータ`](/ja/reference/functions/aggregate-functions/combinators#-map)
