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);