Jump to content

Display Summary Report Using A Simple Query In Mysql


eliza81

Recommended Posts

Hi all, I am sharing a tip with you.Any suggestions are appreciated.And everyone is welcomed to add to this discussion.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 ROLLUPOutput:CONTACT ID TOTAL 117 5118 0119 10GRAND TOTAL 15You can't use the ORDER BY clause with the WITH ROLLUP. They are mutually exclusive.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...