0

我有一个查询,我想用它来删除“已查看”列日期时间值超过 24 小时的数据行。我怎样才能用一个查询来做到这一点?可能吗?

这是我到目前为止所拥有的:

$delete_expired_notifications_query= "DELETE FROM notifications WHERE user_id= 
'".$u_id."' AND viewed (some code that says older than 24hrs)";
    mysqli_query($connect, $delete_expired_notifications_query);
4

3 回答 3

3

假设这viewed是一个 MySQL 时间类型(它应该是):

... AND viewed < NOW() - INTERVAL 24 HOUR
于 2013-01-19T16:26:24.073 回答
2

使用date_Add和间隔,您可以尝试从现在开始超过 24 小时的记录。

DELETE FROM notifications WHERE user_id= 
'".$u_id."' AND viewed < date_Add(now(), interval - 24 hour)
于 2013-01-19T16:27:22.967 回答
1
DELETE FROM notifications WHERE user_id = '".$u_id."' 
      AND viewed < DATE_ADD(NOW(), INTERVAL -1 DAY)";

或者

DELETE FROM notifications WHERE user_id = '".$u_id."' 
      AND viewed < DATE_ADD(NOW(), INTERVAL -24 HOUR)";
于 2013-01-19T17:03:28.907 回答