What is the use of WITH ROLLUP modifier in MySQL?

MySQLMySQLi Database

“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)
raja
Published on 22-Feb-2018 06:08:46
Advertisements