选择* WHERE状态<> '已删除'或状态<> 'completed'AND update_datetime< unix_timestamp(now() - 间隔7天)

时间:2013-04-12 19:22:36

标签: mysql sql datetime

如果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 )

2 个答案:

答案 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_datetimeDATETIME列,请改用:

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 )