Scenes:
According to the table required operation_time
field is more than ten minutes from time as the current conditions, the update data fields
- To use the function:
unix_timestamp(now())
calculates the current time to the1970-01-01 00:00:00'
year the number of seconds - So the SQL to calculate the current time and the number of minutes in a field in the table exceeds 10 minutes is:
SELECT
*
FROM
st_machine sm
WHERE
( unix_timestamp( now())- unix_timestamp( sm.operation_time ) )/ 60 > 10
- Use this as a condition to update other fields SQL as:
UPDATE st_machine sm
SET sm.`online` = 0
WHERE
(
UNIX_TIMESTAMP(
now())- UNIX_TIMESTAMP( sm.operation_time ))/ 60 > 10