GROUP BY Modifiers With  ROLLUP  added, the query produces several extra rows: Now the output includes summary information at four levels of analysis, not just one: The  NULL  indicators in each super-aggregate row are produced when the row is sent to the client. The server looks at the columns named in the  GROUP BY  clause following the leftmost one that has changed value. For any column in the result set with a name that matches any of those names, its value is set to NULL . (If you specify grouping columns by column position, the server identifies which columns to set to NULL  by position.) Because the  NULL  values in the super-aggregate rows are placed into the result set at such a late stage in query processing, you can test them as  NULL  values only in the select list or  HAVING  clause. You cannot 2406 •Following each set of product rows for a given year and country, an extra super-aggregate summary row appears showing the total for all products. These rows have the  product  column set to  NULL . •Following each set of rows for a given year, an extra super-aggregate summary row appears showing the total for all countries and products. These rows have the  country  and  products  columns set to NULL . •Finally, following all other rows, an extra super-aggregate summary row appears showing the grand total for all years, countries, and products. This row has the  year ,  country , and  products  columns set to NULL . | year | country | product | profit | +------+---------+------------+--------+ | 2000 | Finland | Computer | 1500 | | 2000 | Finland | Phone | 100 | | 2000 | India | Calculator | 150 | | 2000 | India | Computer | 1200 | | 2000 | USA | Calculator | 75 | | 2000 | USA | Computer | 1500 | | 2001 | Finland | Phone | 10 | | 2001 | USA | Calculator | 50 | | 2001 | USA | Computer | 2700 | | 2001 | USA | TV | 250 | +------+---------+------------+--------+ +------+---------+------------+--------+ | year | country | product | profit | +------+---------+------------+--------+ | 2000 | Finland | Computer | 1500 | | 2000 | Finland | Phone | 100 | | 2000 | Finland | NULL | 1600 | | 2000 | India | Calculator | 150 | | 2000 | India | Computer | 1200 | | 2000 | India | NULL | 1350 | | 2000 | USA | Calculator | 75 | | 2000 | USA | Computer | 1500 | | 2000 | USA | NULL | 1575 | | 2000 | NULL | NULL | 4525 | | 2001 | Finland | Phone | 10 | | 2001 | Finland | NULL | 10 | | 2001 | USA | Calculator | 50 | | 2001 | USA | Computer | 2700 | | 2001 | USA | TV | 250 | | 2001 | USA | NULL | 3000 | | 2001 | NULL | NULL | 3010 | | NULL | NULL | NULL | 7535 | +------+---------+------------+--------+ mysql>  SELECT year, country, product, SUM(profit) AS profit FROM sales GROUP BY year, country, product WITH ROLLUP;