如果update_datetime列超过7天(MySQL版本2013-04-11 11:22: 44)。
这是我虚弱而失败的尝试:
WHERE
status <> 'deleted'
OR status <> 'completed'
AND update_datetime < unix_timestamp( now() - interval 7 day )
答案 0 :(得分:1)
WHERE
status <> 'deleted'
AND (
(update_datetime < unix_timestamp( now() - interval 7 day ) AND status = 'completed')
OR (update_datetime >= unix_timestamp( now() - interval 7 day ))
)
如果update_datetime
是DATETIME
列,请改用:
WHERE
status <> 'deleted'
AND (
(update_datetime < DATE_SUB(NOW(), INTERVAL 7 day) AND status = 'completed')
OR (update_datetime >= DATE_SUB(NOW(), INTERVAL 7 day))
)
答案 1 :(得分:0)
你是说这个吗?
WHERE
(status <> 'deleted'
OR status <> 'completed')
AND update_datetime < unix_timestamp( now() - interval 7 day )
等于
WHERE
(not status in ('deleted', 'completed'))
AND update_datetime < unix_timestamp( now() - interval 7 day )