如果 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 )
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))
)
你是这个意思吗?
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 )