I am trying to figure out if I can do some math completely within mySQL (5.1) but am not
sure if this is possible. I am not an expert with SQL.
I have two tables. One to track overall time, and one with individiual time entries.
The idea is to keep a running total in Table1 based on what was used in Table2.
Table1:
UserID (INT),
TotalTime (INT)
Table2:
UserID (INT),
TimeUsed (INT),
isCalculated (bool)
What I would like to do is iterate through Table 2 where isCalculated is false and
subtract the Table2.TimeUsed for each entry from the Table1.TotalTime where Table1.UserID=Table2.UserID.
After the calculation I would need to toggle isCalculated to true.
It seems this could be done in a loop, but I am not sure of the proper syntax in mySQL.
Thanks for any guidance.
1 Answer