Let’s assume that I have a table in a mysql database as follows,
date inQty outQty
2011-10-24 700.00 0.0
2011-10-01 500.00 0.0
2011-10-02 500.00 0.0
2011-10-03 550.00 0.0
2011-10-04 100.00 0.0
2011-10-05 200.00 0.0
2011-10-05 0.00 100.0
2011-10-02 0.00 500.0
2011-10-03 0.00 150.0
2011-10-24 200.00 0.0
and from above table I need to query following result,
date inQty outQty Balance
2011-10-24 700.00 0.0 700.00
2011-10-01 500.00 0.0 500.00
2011-10-02 500.00 0.0 500.00
2011-10-03 550.00 0.0 550.00
2011-10-04 100.00 0.0 100.00
2011-10-05 200.00 0.0 200.00
2011-10-05 0.00 100.0 100.00
2011-10-02 0.00 500.0 0.0
2011-10-03 0.00 150.0 400.00
2011-10-24 200.00 0.0 500.00
how can I get this from a SQL query?
I reckon you’re looking for a cumulative sum over a partition. This is only a guess though since your post is rather unclear since there is no clear pattern to the data. I think I understand what you’re driving at though…
Perhaps you can review and edit your post to make the question clearer?
Anyway, give this a go. I don’t know what your table is called so I’ll post my own example.