Home  >  Article  >  Database  >  How can we get the summary output of a column in the MySQL result set?

How can we get the summary output of a column in the MySQL result set?

王林
王林forward
2023-09-16 18:17:061158browse

How can we get the summary output of a column in the MySQL result set?

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.

Example

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete