We can get the summary output of a column in the MySQL result set by using the "WITH ROLLUP" modifier. This modifier is used with the GROUP BY clause. It gives summary output, including extra rows representing higher-level summary operations.
In this example, the WITH ROLLUP modifier gives a summary output of the total cost value in an extra line.
mysql> Select Item_name, SUM(Cost) AS Total_cost from Item_list GROUP BY Item_name WITH ROLLUP; +-----------+------------+ | Item_name | Total_cost | +-----------+------------+ | Notebook | 45.00 | | Pen | 31.70 | | Pencilbox | 125.20 | | NULL | 201.90 | +-----------+------------+ 4 rows in set (0.00 sec)
The above is the detailed content of How can we get the summary output of a column in the MySQL result set?. For more information, please follow other related articles on the PHP Chinese website!