Reputation: 23
I have table columns workhours
and overtime
, and I would like to do a SQL or PHP query that checks if the workinghours are over 8 hours and if so it UPDATE
s the worked overtime to overtime column.
Here's my table:
id workinghours overtime
1, 4.79, ---
2, 8.73, ---
3, 7.97, ---
For example on the second row there is 8.73 hours of work and so it would update the 0.73 hours to the overtime column.
Upvotes: 0
Views: 940
Reputation: 3852
query :
update work set overtime= (case when working > 8 then (working - 8) else null end);
check SQL Fiddle Demo
Upvotes: 1
Reputation: 3362
Try something like this:
update mytable
set overtime =
case when workinghours > 8 then workinghours - 8 else 0 end
;
Upvotes: 1