Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The ROLLUP clause extends GROUP BY to return a row containing a subtotal for each group along with a total for all groups. As you saw in Chapter 3, you use GROUP BY to group rows into blocks with a common column value. For example, the following query uses GROUP BY to group the rows from the employees2 table by department_id and uses SUM() to get the sum of the salaries for each division_id:
SELECT division_id, SUM(salary) FROM employees2 GROUP BY division_id; DIV SUM(SALARY) --- ----------- BUS 1610000 OPE 1320000 SAL 4936000 SUP 1015000