Skip to content
Advertisement

SQL Grand Total row from Multi table Select Query

I have been able to use the below SQL query to give me 4 rows of data

This gives me a breakdown of the orders as I need but I also want to have a Grand Total row that sums each column.

If I insert the above sql query into the below

I get one single line with the correct totals but no breakdown rows.

How can I do this so it displays the four rows of each type and a grand total row at the bottom.

Advertisement

Answer

Use common table expressions (CTE).

Note: I added formatting the total values to ensure the total values of NetAmount and MarginAmount to share the same data type as the breakdown values. Consider to remove formatting the values from your query and add it to the presentation layer of your application.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement