Home > Database > Mysql Tutorial > 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?

王林
Release: 2023-09-16 18:17:06
forward
1181 people have browsed it

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template