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

# avgMap

> avgMap 조합자를 사용하는 예시

<div id="description">
  ## 설명
</div>

[`맵`](/ko/reference/functions/aggregate-functions/combinators#-map) 조합자는 [`avg`](/ko/reference/functions/aggregate-functions/avg)
함수에 적용할 수 있으며, `avgMap`
집계 조합자 함수를 사용해 각 키별로 맵의 값에 대한 산술 평균을 계산합니다.

<div id="example-usage">
  ## 예시 사용법
</div>

이 예시에서는 서로 다른 시간 슬롯의 상태 코드와 해당 개수를 저장하는 테이블(table)을 생성합니다.
각 행에는 상태 코드와 해당 개수를 담은 맵이 포함됩니다. 각 시간 슬롯 내에서 상태 코드별 평균 개수를 계산하기 위해
`avgMap`을 사용합니다.

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

`avgMap` 함수는 각 타임슬롯에서 각 상태 코드의 평균 개수를 계산합니다. 예시는 다음과 같습니다.

* 타임슬롯 '2000-01-01 00:00:00':
  * 상태 'a': 15
  * 상태 'b': 25
  * 상태 'c': (35 + 45) / 2 = 40
  * 상태 'd': 55
  * 상태 'e': 65
* 타임슬롯 '2000-01-01 00:01:00':
  * 상태 'd': 75
  * 상태 'e': 85
  * 상태 'f': (95 + 105) / 2 = 100
  * 상태 'g': (115 + 125) / 2 = 120

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

<div id="see-also">
  ## 관련 항목
</div>

* [`avg`](/ko/reference/functions/aggregate-functions/avg)
* [`맵 조합자`](/ko/reference/functions/aggregate-functions/combinators#-map)
