Skip to main content

Using Filtered Aggregates

ClickHouse provides a simple and intuitive way to write filtered aggregates. For example, compare the standard SQL way to write filtered aggregates (which work fine in ClickHouse) with the shorthand syntax using the -If aggregate function combinator, which can be appended to any aggregate function:
Similarly, there is a -Distinct aggregate combinator:
Why are filtered aggregates are important? Because they allow you to implement the “segment comparison” feature in web analytics services. For example:
Check out the aggregate function combinator page in the docs for more details.
Last modified on July 1, 2026