i try to make the running sum of quantity using query
with a expected output

ID    | Date_in | Date_out | Quantity_in | Quantity_out | Quantity_Run_Sum
in01  |17/2/2011|          |    300      |        0     |          300
in02  |17/2/2011|          |    400      |        0     |          700
Out01 |         |20/2/2011 |     0       |        100   |          600
Out02 |         |20/2/2011 |     0       |        100   |          500
in03  |21/2/2011|          |     10      |         0    |          510
Out04 |         |21/2/2011 |      0      |         10   |          500

but what i get is

ID    | Date_in | Date_out | Quantity_in | Quantity_out | Quantity_Run_Sum
in01  |17/2/2011|          |    300      |        0     |          300
in02  |17/2/2011|          |    400      |        0     |          700
Out01 |         |20/2/2011 |     0       |        100   |          610
Out02 |         |20/2/2011 |     0       |        100   |          510
in03  |21/2/2011|          |     10      |         0    |          710
Out04 |         |21/2/2011 |      0      |         10   |          500

Recommended Answers

All 2 Replies

I suspect it is your orderby clause. The running sum would be in order but you force an order by date, which throws off the sum. You'll probably have to do two queries: first that orders the data, second that generates the output.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.