We take pride in your success. We let our positivity drive us, day in and out. Talk to us at Mindfire to know us more.

Software Technology Tips

In MYSQL GROUP BY provide us a modifier called WITH ROLLUP, which will added an extra row to the output as a summary report.

For Example:

Suppose we have a Sales table having SalesId, ContactId and SalesTotal. If we need a summary report, which will display total SalesTotal group by its ContactId.
This can be done using a simple query:

SELECT IFNULL(`ContactId` , "GRAND TOTAL") AS 'CONTACT ID', SUM(`SalesTotal`) AS `TOTAL`  FROM  Sales  GROUP BY  `ContactId`  WITH ROLLUP
Output:

CONTACT ID  TOTAL
117 5
118 0
119 10
GRAND TOTAL 15

You can't use the ORDER BY clause with the WITH ROLLUP. They are mutually exclusive.


Related Tags:

Database, MySQL, Reporting

Author: Madhusmita Pradhan

top

Database

Let us Connect!

privacy

copyright (c) Mindfire Solutions 2007-2012. Login