content_image/838450.jpg content_image/838453.jpg content_image/838454.jpg
A simple ROLLUP  operation produces these results, in which it is not so easy to distinguish NULL  values in super-aggregate rows from NULL  values in regular grouped rows: 

mysql> SELECT name, size, SUM(quantity) AS quantity FROM t1 GROUP BY name, size WITH ROLLUP; 

<img src='content_image/838450.jpg'>

Using GROUPING()  to substitute labels for the super-aggregate NULL  values makes the result easier to interpret: 

## Other Considerations When using ROLLUP 

mysql> SELECT IF(GROUPING(name) = 1, ’All items’, name) AS name, IF(GROUPING(size) = 1, ’All sizes’, size) AS size, SUM(quantity) AS quantity FROM t1 GROUP BY name, size WITH ROLLUP; 

<img src='content_image/838453.jpg'>

The following discussion lists some behaviors specific to the MySQL implementation of ROLLUP . 

Prior to MySQL 8.0.12, when you use ROLLUP , you cannot also use an ORDER BY  clause to sort the results. In other words, ROLLUP  and ORDER BY  were mutually exclusive in MySQL. However, you still have some control over sort order. To work around the restriction that prevents using ROLLUP  with ORDER BY and achieve a specific sort order of grouped results, generate the grouped result set as a derived table and apply ORDER BY  to it. For example: 

mysql> SELECT * FROM (SELECT year, SUM(profit) AS profit FROM sales GROUP BY year WITH ROLLUP) AS dt ORDER BY year DESC; 

<img src='content_image/838454.jpg'>

