What is the Use of "WITH ROLLUP" in Mysql?
Top Questions
Adding a WITH ROLLUP modifier to the GROUP BY clause causes the query to produce another row.
eg:
mysql> SELECT year, SUM(profit) FROM sales GROUP BY year WITH ROLLUP;
+------+-------------+
| year | SUM(profit) |
+------+-------------+
| 2000 | 4525 |
| 2001 | 3010 |
| NULL | 7535 | <<<- Note here*
+------+-------------+
So an extra row (<<<- Note here*) is created by mysql and also we get total profit
in the last column.
Post new comment