I have two tables :
Order :
date | Product | Quantity
01/03| P1 | 2
01/03| P2 | 2
02/03| P1 | 3
02/03| P2 | 1
02/03| P3 | 5
Stock :
Purchase number | product | Quantity
01/03 | P1 | 4
01/03 | P2 | 1
02/03 | P2 | 2
02/03 | P3 | 5
02/03 | P1 | 1
02/03 | P1 | 1
The first table is my order (what I sold), with this table I want to update the second table (which is my stock) to know exactly what i have in stock. But i want to do that following the date, I first update the Quantity.Stock 01/03 before 02/03 . Right now I have a loop , the problem is I don't want to have any " -1 " and i don't want to update all the rows with the same data . In this example I have 5 P1 in order so in stock the first line of P1 must be 0 , the next P1 line must be 0 too but the last line must stay at 1 .
Any ideas ? or direction ?
Bruno