Miscellaneous Functions +------+------+----------+ | name | size | quantity | +------+------+----------+ | ball | NULL | 35 | | hoop | NULL | 23 | | NULL | NULL | 58 | +------+------+----------+ result for GROUPING( expr3 ) + result for GROUPING( expr2 ) << 1 + result for GROUPING( expr1 ) << 2 mysql>  SELECT name, size, SUM(quantity) AS quantity, GROUPING(name) AS grp_name, GROUPING(size) AS grp_size, GROUPING(name, size) AS grp_all FROM t1 GROUP BY name, size WITH ROLLUP; +------+-------+----------+----------+----------+---------+ | name | size | quantity | grp_name | grp_size | grp_all | +------+-------+----------+----------+----------+---------+ | ball | NULL | 5 | 0 | 0 | 0 | | ball | large | 20 | 0 | 0 | 0 | | ball | small | 10 | 0 | 0 | 0 | | ball | NULL | 35 | 0 | 1 | 1 | | hoop | NULL | 3 | 0 | 0 | 0 | | hoop | large | 5 | 0 | 0 | 0 | | hoop | small | 15 | 0 | 0 | 0 | | hoop | NULL | 23 | 0 | 1 | 1 | | NULL | NULL | 58 | 1 | 1 | 3 | +------+-------+----------+----------+----------+---------+ mysql>  SELECT name, size, SUM(quantity) AS quantity FROM t1 GROUP BY name, size WITH ROLLUP HAVING GROUPING(name, size) <> 0; +------+------+----------+ | name | size | quantity | +------+------+----------+ | ball | NULL | 35 | | hoop | NULL | 23 | | NULL | NULL | 58 | With multiple expression arguments, the  GROUPING()  return value is nonzero if any expression represents a super-aggregate value. Multiple-argument  GROUPING()  syntax thus provides a simpler way to write the earlier query that returned only super-aggregate rows, by using a single multiple- argument  GROUPING()  call rather than multiple single-argument calls: The following query shows how  GROUPING()  results for single arguments combine for a multiple- argument call to produce a bitmask value: GROUPING()  permits multiple expression arguments. In this case, the  GROUPING()  return value represents a bitmask combined from the results for each expression, where the lowest-order bit corresponds to the result for the rightmost expression. For example, with three expression arguments, GROUPING( expr1 ,  expr2 ,  expr3 )  is evaluated like this: 2443