Home > Software engineering >  display grand total sales in column
display grand total sales in column

Time:07-13

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

CodePudding user response:

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.

  • Related