ROLLUP with Partial Grouping
ROLLUP with Partial Grouping is a SQL statement in the Aggregate Functions category. ROLLUP can be applied to a subset of GROUP BY columns, not all of them. Useful for mixed-level summaries. The syntax is SELECT col1, col2, SUM(val) FROM t GROUP BY col1, ROLLUP(col2);. It returns partial rollup result. A close relative is COUNT(), which returns the number of rows (or non-NULL values) in a group. A close relative is SUM(), which returns the sum of all non-NULL values in a group. Works with numeric columns. A close relative is AVG(), which returns the average (mean) of all non-NULL values in a group. More about this category: Aggregation functions — COUNT, SUM, AVG, MIN, MAX, GROUP BY, HAVING. Related Aggregate Functions entries: COUNT(), SUM(), AVG(), MIN(), MAX(), GROUP_CONCAT() / LISTAGG(), STRING_AGG(), VARIANCE() / VAR_SAMP(). This page is part of the free SQL Reference documentation covering 762+ statements, functions, and clauses, each with syntax, parameters, return values, and examples for MySQL, PostgreSQL, SQL Server, and SQLite.