I have sales data for branches. I want a SQL which will give me summary of sales data for each branchId as below, of course BranchId(s) are huge so I have to make it dynamic (I can't use Union). I am stuck how to add a summary row after every branch change dynamically.
+ ---------+--------+---------+-----------+ | BranchId | CashIn | CashOut | CardSales | + ---------+--------+---------+-----------+ | 1 | 1000 | 500 | 50 | | 1 | 500 | 2500 | 100 | | 1 | 1000 | 200 | 200 | | Totals | 2500 | 3200 | 350 | | 5 | 100 | 500 | 500 | | Totals | 100 | 500 | 500 | | 7 | 100 | 100 | 100 | | 7 | 200 | 300 | 400 | | Totals | 300 | 400 | 500 | + ---------+--------+---------+-----------+