Hello again,
The problem are duplicate date (fecha) values, why sum will be wrongly computed. To solve this, date and uniqueID must be combined in that order because date has higher priority than uniqueID (I think so). In the expression string(b.fecha, b.uniqueID) 1st, date and uniqueID will be converted to chars and 2nd, both chars will be concatenated, for example string(2008-03-05, '.', 10006) results in '2008-03-05.10006'. Now duplicates are impossible ! The following select statement
SELECT uniqueID, fecha as "Date", Amount, amount + coalesce((SELECT sum(amount) FROM ozr b WHERE string(b.fecha, '.', b.uniqueID) < string(a.fecha, '.', a.uniqueID) ), 0) as sAmount, string("Date", '.', uniqueID) as "test only" FROM ozr a ORDER BY string("Date", '.', uniqueID);
gives the result you are asking for:
uniqueID DATE Amount sAmount test only
----------------------------------------------------------
10006 2008-03-05 233.00 233.00 2008-03-05.10006
10007 2008-03-05 -33.00 200.00 2008-03-05.10007
10005 2008-04-05 40.00 240.00 2008-04-05.10005
10004 2008-05-05 -20.00 220.00 2008-05-05.10004
What you have to do is, you should find an appropriate function, like string(), what concatenates strings on your database, if MySql, CONCAT() might solve it. Possibly, you have to convert date type (b.fecha) and integer type (b.uniqueID) into varchars first. On my database system this task is done automatically.
-----
tesu