ROLLUP and CUBE

Published July 26, 2025 By Sai Sree Ram Gundepudi

ROLLUP and CUBE

ROLLUP

ROLLUP adds subtotals and grand totals in a hierarchy.

SELECT department_id, job_id, SUM(salary)
FROM employees
GROUP BY ROLLUP(department_id, job_id);

CUBE

CUBE provides all possible combinations of aggregations.

SELECT department_id, job_id, SUM(salary)
FROM employees
GROUP BY CUBE(department_id, job_id);

Was this solution helpful?

Your feedback helps improve our technical knowledge repository.

Share this article