Problems / Multi-Level Aggregation Report / Editorial
Multi-level aggregation produces summary rows at different granularities in a single result set.
GROUP BY region, category
GROUP BY region
'ALL'
Combine with UNION ALL and add a level label to distinguish the aggregation level.
level
DuckDB supports:
```sql
SELECT
COALESCE(region, 'ALL') AS region,
COALESCE(category, 'ALL') AS category,
SUM(amount) AS total_amount
FROM store_sales
GROUP BY GROUPING SETS (
(region, category),
(region),
()
)
```
GROUPING SETS is more concise but less explicit about the aggregation semantics. The UNION ALL approach is clearer for learning.
Solve Multi-Level Aggregation Report yourself →