With multiple expression arguments,  GROUPING()  returns a result representing a bitmask the combines the results for each expression, with the lowest-order bit corresponding to the result for the rightmost expression. For example,  GROUPING(year, country, product)  is evaluated like this: The result of such a  GROUPING()  is nonzero if any of the expressions represents a super-aggregate NULL , so you can return only the super-aggregate rows and filter out the regular grouped rows like this: The  sales  table contains no  NULL  values, so all  NULL  values in a  ROLLUP  result represent super- aggregate values. When the data set contains  NULL  values,  ROLLUP  summaries may contain  NULL  values not only in super-aggregate rows, but also in regular grouped rows.  GROUPING()  enables these to be distinguished. Suppose that table  t1  contains a simple data set with two grouping factors for a set of quantity values, where  NULL  indicates something like “other”  or “unknown” : mysql>  SELECT * FROM t1; mysql>  SELECT year, country, product, SUM(profit) AS profit FROM sales GROUP BY year, country, product WITH ROLLUP HAVING GROUPING(year, country, product) <> 0; | 2000 | Finland | Computer | 1500 | | 2000 | Finland | Phone | 100 | | 2000 | Finland | All products | 1600 | | 2000 | India | Calculator | 150 | | 2000 | India | Computer | 1200 | | 2000 | India | All products | 1350 | | 2000 | USA | Calculator | 75 | | 2000 | USA | Computer | 1500 | | 2000 | USA | All products | 1575 | | 2000 | All countries | All products | 4525 | | 2001 | Finland | Phone | 10 | | 2001 | Finland | All products | 10 | | 2001 | USA | Calculator | 50 | | 2001 | USA | Computer | 2700 | | 2001 | USA | TV | 250 | | 2001 | USA | All products | 3000 | | 2001 | All countries | All products | 3010 | | All years | All countries | All products | 7535 | +-----------+---------------+--------------+--------+ result for GROUPING( product ) + result for GROUPING( country ) << 1 + result for GROUPING( year ) << 2 +------+---------+---------+--------+ | year | country | product | profit | +------+---------+---------+--------+ | 2000 | Finland | NULL | 1600 | | 2000 | India | NULL | 1350 | | 2000 | USA | NULL | 1575 | | 2000 | NULL | NULL | 4525 | | 2001 | Finland | NULL | 10 | | 2001 | USA | NULL | 3000 | | 2001 | NULL | NULL | 3010 | | NULL | NULL | NULL | 7535 | +------+---------+---------+--------+ +------+-------+----------+ | name | size | quantity | +------+-------+----------+ | ball | small | 10 | | ball | large | 20 | | ball | NULL | 5 | | hoop | small | 15 | | hoop | large | 5 | | hoop | NULL | 3 | +------+-------+----------+ 2408 GROUP BY Modifiers