I have a table that looks like
id
Type: Auto inc-int
Comment: the unique id
Value Inserted auto inc int
dateGained
Type: dateTime
Comment: Date currency was gained
Value inserted: Current Date/Time
amntGained
Type: float
Comment: Amount of currency gained
Value inserted: value gained (e.g. 0.25)
amntUsed
Type: float
Comment: When part of the value is used this column gets updated
Value inserted: 0
uuid
Type: uuid
Comment: The users uuid
Value inserted: (a uuid)
so a few example rows (for a single user) would be
1 | 2010-07-30 00:00:00 | 0.25 | 0.20 | [uuid]
2 | 2010-08-12 00:00:00 | 1.75 | 0.00 | [uuid]
3 | 2010-08-17 00:00:00 | 8.25 | 0.00 | [uuid]
4 | 2010-09-15 00:00:00 | 0.05 | 0.00 | [uuid]
Now my question is around the logic:
Basically I have a function that is given a uuid and an amount, the function then has to go through starting from the oldest and update the used value untill the amount given is satisfied.
e.g. if the function was given 6.25 and [uuid]
The table would look like
1 | 2010-07-30 00:00:00 | 0.25 | 0.25 | [uuid] //still need to use 6.20
2 | 2010-08-12 00:00:00 | 1.75 | 1.75 | [uuid] //still need to use 4.45
3 | 2010-08-17 00:00:00 | 8.25 | 4.45 | [uuid] //we now have 3.80 remaining
4 | 2010-09-15 00:00:00 | 0.05 | 0.00 | [uuid] //this row is untouched
but I have a complete mind blank on how to do this efficiently or at all for that matter.
Will it work for you? (Updated version)
For your data: