What is the use of WITH ROLLUP modifier in MySQL?


“WITH ROLLUP” is a modifier that is used with GROUP BY clause. Mainly, it causes the summary output to include extra rows that represent higher-level summary operations.

Example

In the example below, WITH ROLLUP modifier gave the summary output with total price value in the extra row.

mysql> Select Item, SUM(Price) AS Price from ratelist Group by item WITH ROLLUP;
+------+-------+
| Item | Price |
+------+-------+
| A    |   502 |
| B    |   630 |
| C    |  1005 |
| h    |   850 |
| T    |   250 |
| NULL |  3237 |
+------+-------+
6 rows in set (0.00 sec)

Updated on: 22-Jun-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements