Hello
Lets said I have a table with id, date, amount
id | date | amount
1 | 12/1/2000 | 10
1 | 12/2/2000 | 3
2 | 12/3/2000 | 6
1 | 12/4/2000 | 5
If there is a sale in id=1 that is 15 then amount from id=1 will be decreased sorted by oldest date. So the result :
id | date | amount
1 | 12/1/2000 | 0
1 | 12/2/2000 | 0
2 | 12/3/2000 | 6
1 | 12/4/2000 | 3
Can I do it in sql? Pls give me some direction.