Monday, 26 August 2019

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)

0 comments:

Post a Comment