---
title: "SQL Dynamic Column Selection with ClickHouse"
description: "ClickHouse's COLUMNS clause selects columns by regular expression, so you can aggregate over a subset of a wide table without listing every column."
url: "https://swe.quest/articles/sql-dynamic-column-selection-with-clickhouse-ad8aa24030ce2bb7"
canonical: "https://clickhouse.com/blog/sql-dynamic-column-selection-clickhouse"
source: "ClickHouse"
published: "2023-11-28"
difficulty: "medium"
kind: "How-to"
reading_minutes: 4
tags: ["sql","analytics"]
---

# SQL Dynamic Column Selection with ClickHouse

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2023-11-28, 4 min read, How-to. Original: [https://clickhouse.com/blog/sql-dynamic-column-selection-clickhouse](https://clickhouse.com/blog/sql-dynamic-column-selection-clickhouse)

## Summary

ClickHouse's COLUMNS clause selects columns by regular expression, so you can aggregate over a subset of a wide table without listing every column. Using the NYC yellow taxi dataset loaded into ClickHouse Local, the walkthrough shows how APPLY runs functions or lambdas across the matched columns, including chained aggregation and rounding. REPLACE swaps individual column expressions while leaving the rest unchanged, and EXCEPT drops columns from the match. Together these clauses cut down repetitive typing in analytical SQL.

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 basics ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))
- regular expressions

## Keywords

ClickHouse, ClickHouse Local, COLUMNS, APPLY, Parquet, NYC taxi dataset

## Related posts

- [ClickHouse Release 26.4](https://swe.quest/articles/clickhouse-release-26-4-f4f5532396f893cd.md): ClickHouse · 2026-05-08 · Medium · 10 min read · Analytics & OLAP, SQL, Query engines, Performance engineering
  ClickHouse 26.4 ships 39 features, 45 performance optimizations and 238 bug fixes, led by SQL-compatibility additions: VALUES as a table expression with column aliases, PostgreSQL-style EXTRACT units, SET TIME ZONE, NATURAL JOIN and compound INTERVAL literals.
- [Using Aggregate Combinators in ClickHouse](https://swe.quest/articles/using-aggregate-combinators-in-clickhouse-c05d4b9a82a2b37a.md): ClickHouse · 2023-02-08 · Medium · 11 min read · SQL, Analytics & OLAP
  ClickHouse aggregate combinators are suffixes appended to aggregate function names, and they can be chained, as in sumArrayIfOrNull.
- [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.
- [Querying Pandas DataFrames with ClickHouse](https://swe.quest/articles/querying-pandas-dataframes-with-clickhouse-f6443dd364e0e7c9.md): ClickHouse · 2023-11-15 · Medium · 4 min read · Python, Analytics & OLAP, SQL
  chDB, an embedded Python library built on the ClickHouse engine, can run SQL directly against Pandas DataFrames through the chdb.dataframe module.
- [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.

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)
