I am executing a cumulative sum order by date and I do not get the expected result. Some records are presented in a different order compared to the order used for the sum.
Please have a look at SQL Fiddle
I would expect either the following result:
2015-05-05T00:00:00Z 50 30 20 90 120
2015-05-05T00:00:00Z 60 30 30 120 100
2015-05-04T00:00:00Z 70 50 20 30 70
2015-05-04T00:00:00Z 80 40 40 70 50
2015-05-03T00:00:00Z 30 20 10 10
or the following order:
2015-05-05T00:00:00Z 60 30 30 120
2015-05-05T00:00:00Z 50 30 20 90
2015-05-05T00:00:00Z 60 30 30 120
2015-05-04T00:00:00Z 80 40 40 70
2015-05-04T00:00:00Z 70 50 20 30
2015-05-04T00:00:00Z 80 40 40 70
2015-05-03T00:00:00Z 30 20 10 10
(Added) please note that negative values are also possible. This is the reason why I have mentioned on answers below that an order on the cumulative sum would not solve the problem. As an example I will modify slightly the result:
2015-05-05T00:00:00Z 30 60 -30 60
2015-05-05T00:00:00Z 50 30 20 90
2015-05-04T00:00:00Z 80 40 40 70
2015-05-04T00:00:00Z 70 50 20 30
2015-05-03T00:00:00Z 30 20 10 10
Thanks for the help.