---
title: "Using Aggregate Combinators in ClickHouse"
description: "ClickHouse aggregate combinators are suffixes appended to aggregate function names, and they can be chained, as in sumArrayIfOrNull."
url: "https://swe.quest/articles/using-aggregate-combinators-in-clickhouse-c05d4b9a82a2b37a"
canonical: "https://clickhouse.com/blog/aggregate-functions-combinators-in-clickhouse-for-arrays-maps-and-states"
source: "ClickHouse"
published: "2023-02-08"
difficulty: "medium"
kind: "How-to"
reading_minutes: 11
tags: ["sql","analytics"]
---

# Using Aggregate Combinators in ClickHouse

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2023-02-08, 11 min read, How-to. Original: [https://clickhouse.com/blog/aggregate-functions-combinators-in-clickhouse-for-arrays-maps-and-states](https://clickhouse.com/blog/aggregate-functions-combinators-in-clickhouse-for-arrays-maps-and-states)

## Summary

ClickHouse aggregate combinators are suffixes appended to aggregate function names, and they can be chained, as in sumArrayIfOrNull. They change how an aggregation behaves without restructuring tables. If computes several conditional aggregates in one query, Distinct deduplicates inputs, and Resample buckets data into fixed-step groups, which arrayZip and arrayJoin can turn back into rows. OrDefault and OrNull control what empty result sets return, while Array and Map aggregate the contents of array and map columns, with worked SQL examples on sample payments and article-read tables.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [SQL](https://swe.quest/tags/sql.md) (Languages)
- [Analytics & OLAP](https://swe.quest/tags/analytics.md) (Data & databases)

## Prerequisites

- SQL aggregate functions ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))
- ClickHouse basics ([easy posts on Analytics & OLAP](https://swe.quest/tags/analytics.md?difficulty=easy))

## Keywords

ClickHouse, sumIf, Resample, Array combinator, Map combinator, MergeTree

## Related posts

- [ClickHouse Newsletter March 2023: Contributing to ClickHouse](https://swe.quest/articles/clickhouse-newsletter-march-2023-contributing-to-clickhouse-86808ac436001235.md): ClickHouse · 2023-03-23 · Medium · 6 min read · SQL, Analytics & OLAP
  ClickHouse v23.2 ships 18 new features, 30 performance optimisations and 43 bug fixes, headlined by multi-stage PREWHERE, read support for Apache Iceberg v1 tables, and correlation matrix computation.
- [ClickHouse vs. Elasticsearch: The Mechanics of Count Aggregations](https://swe.quest/articles/clickhouse-vs-elasticsearch-the-mechanics-of-count-aggregations-fa943a94e2c565e4.md): ClickHouse · 2024-05-07 · Medium · 15 min read · Query engines, Analytics & OLAP, Search, Performance engineering
  ClickHouse runs count(\*) GROUP BY aggregations in parallel at three levels: SIMD within column values, multiple cores over arbitrary data ranges, and multiple nodes over shards.
- [SQL Dynamic Column Selection with ClickHouse](https://swe.quest/articles/sql-dynamic-column-selection-with-clickhouse-ad8aa24030ce2bb7.md): ClickHouse · 2023-11-28 · Medium · 4 min read · SQL, Analytics & OLAP
  ClickHouse's COLUMNS clause selects columns by regular expression, so you can aggregate over a subset of a wide table without listing every column.
- [ClickHouse release 26.10](https://swe.quest/articles/clickhouse-release-26-10-f1505265758ca672.md): ClickHouse · 2026-11-06 · Medium · 23 min read · Analytics & OLAP, SQL, Query engines
  ClickHouse 26.10 ships 104 features, 225 performance optimizations and 739 bug fixes.
- [Join Types supported in ClickHouse](https://swe.quest/articles/join-types-supported-in-clickhouse-41a687e1e862f9b6.md): ClickHouse · 2023-03-02 · Medium · 13 min read · SQL, Analytics & OLAP, Query engines, Databases
  ClickHouse supports all standard SQL join types plus analytics-oriented variants: INNER, LEFT/RIGHT/FULL OUTER, CROSS, LEFT/RIGHT SEMI, LEFT/RIGHT ANTI, LEFT/RIGHT/INNER ANY, and ASOF joins.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
