I want to get the time average by using this command in PHP :
SELECT SEC_TO_TIME(AVG(TIME_TO_SEC(PunchInTime))) as Average from AverageOnTime;
so is this code below correct to combine update and avg:
UPDATE table_3_2020 SET pastTime = SEC_TO_TIME(AVG(TIME_TO_SEC(currentTime))) WHERE id = '1'
I have two requests:
- I want to UPDATE another column with the average, so how can I do that?
- When I use the above SELECT I got the HH:MM but I just want the minutes only without the hours.
Advertisement
Answer
Try this
UPDATE table_3_2020 SET pastTime = (SELECT SEC_TO_TIME(AVG(TIME_TO_SEC(PunchInTime))) as Average from AverageOnTime) WHERE id = '1';