Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

display grand total sales in column

how to display month sales grand total in column for this query

select CONCAT(month(date),'-',YEAR(DATE)) as month, branch ,sum(total) as total
from BRANCH_SALES
where  DATE  between '20220101' and '20220131' and branch = '701'
group by CONCAT(month(date),'-',YEAR(DATE)),
Branch
ORDER BY total

what I’m looking for

month branch total grand total
01-2022 701 2345 7845
01-2022 702 4000 7845
01-2022 703 1500 7845

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Just use a windowed SUM:

SUM(SUM(total)) OVER () AS GrandTotal

As the OVER clause doesn’t have a PARTITION BY or ORDER BY clause, it’ll give a SUM for the entire dataset.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading