1

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

2 回答 2

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))
)
于 2013-04-12T19:51:23.080 回答
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 )
于 2013-04-12T19:50:02.493 回答