2

I am trying to get a list, a total, and a cumulative total in the same column. So far I have the list and the total for that date range, but moving forward I would like to get a cumulative total. Here is the code i'm using, please note temp_2 and temp_3 yield the same results;

Select School,Principal, NumberOfObs    
From temp_2     
Union     
Select '','TOTAL',Sum(NumberOfObs)     
From temp_3;

enter image description here

Any thoughts?

Shadow
  • 33,525
  • 10
  • 51
  • 64
  • 4
    My thoughts: Why union? Look at [group by modifier](http://dev.mysql.com/doc/refman/5.7/en/group-by-modifiers.html) `with rollup` for total and for the running total look at using user variables like in [this prior stack question](http://stackoverflow.com/questions/5032360/running-sums-for-multiple-categories-in-mysql) – xQbert Dec 22 '15 at 14:05
  • 1
    Plus this seems to require pivoting as well – Shadow Dec 22 '15 at 14:13
  • Is this a duplicate of [Calculate a running total in MySQL](http://stackoverflow.com/q/664700/3664960) – davejal Dec 22 '15 at 14:38
  • I don't think its a duplicate of that, because i'm wanting the cumulative total at the bottom of the column, not in an extra column. I'm still working my way through it. – Aidandebradney Dec 22 '15 at 14:58

0 Answers0