Skip to content
Advertisement

How to create a summary table with subheadings in SQL?

I am using PostgreSQL to create summaries from data using a python script. I had large amounts of data in my SQL table and using the following query I was able to get the required data. Below is my query:

JavaScript

And below is the table created:

JavaScript

I am trying to create a query on this table to further create a summary shown below:

JavaScript

I want to make a query to create a summary like above. Is this possible using SQL and can I directly execute a query on my first query without creating the new table and directly creating the final summary? for ex.

JavaScript

Thank you

Advertisement

Answer

you can get the values you want by this query , but the way you want to show it , should be done in the UI in your app:

JavaScript

group by rollup gives you grand total as well.

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