GROUP BY Modifiers 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: Using  GROUPING()  to substitute labels for the super-aggregate  NULL  values makes the result easier to interpret: +------+-------+----------+ | name | size | quantity | +------+-------+----------+ | ball | NULL | 5 | | ball | large | 20 | | ball | small | 10 | | ball | NULL | 35 | | hoop | NULL | 3 | | hoop | large | 5 | | hoop | small | 15 | | hoop | NULL | 23 | | NULL | NULL | 58 | +------+-------+----------+ mysql>  SELECT name, size, SUM(quantity) AS quantity FROM t1 GROUP BY name, size WITH 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; +-----------+-----------+----------+ | name | size | quantity | +-----------+-----------+----------+ | ball | NULL | 5 | | ball | large | 20 | | ball | small | 10 | | ball | All sizes | 35 | | hoop | NULL | 3 | | hoop | large | 5 | | hoop | small | 15 | | hoop | All sizes | 23 | | All items | All sizes | 58 | +-----------+-----------+----------+ +------+--------+ | year | profit | +------+--------+ | 2001 | 3010 | | 2000 | 4525 | | NULL | 7535 | +------+--------+ mysql>  SELECT * FROM (SELECT year, SUM(profit) AS profit FROM sales GROUP BY year WITH ROLLUP) AS dt ORDER BY year DESC; Other Considerations When using ROLLUP 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: 2409