- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can we get the summary output of a column in MySQL result set itself?
We can get the summary output of a column in MySQL result set by using the “WITH ROLLUP” modifier. This modifier is used with GROUP BY CLAUSE. It gives the summary output to include extra rows that represent higher-level summary operations.
Example
In this example, the WITH ROLLUP modifier gave the summary output with total cost value in the extra row.
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)
Advertisements