MySQL 从 1 小时前选择的 Sql 查询?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4451385/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 18:01:19  来源:igfitidea点击:

Sql query to select from 1 hour ago?

sqlmysql

提问by Mark

I have this query but I want to change the date to delete everything that is from more than 1 hour ago based on the server time (or if not possible by server time by post date). How do I do that?

我有这个查询,但我想更改日期以根据服务器时间删除超过 1 小时前的所有内容(或者如果不可能按发布日期按服务器时间)。我怎么做?

DELETE FROM wp_posts
 WHERE post_date < '2008-06-06 19:18:00' 
   AND post_status = 'publish'

回答by OMG Ponies

Use:

用:

DELETE FROM wp_posts
 WHERE post_date < DATE_SUB(NOW(), INTERVAL 1 HOUR)
   AND post_status = 'publish'

Reference:

参考:

回答by Vadym Tyemirov

Or even simpler:

或者更简单:

SELECT NOW() - INTERVAL 1 HOUR;

So the query becomes:

所以查询变成:

DELETE FROM wp_posts
 WHERE post_date < NOW() - INTERVAL 1 HOUR
   AND post_status = 'publish'

回答by Aminah Nuraini

Subdate function works too!

子日期功能也适用!

SELECT subdate(current_timestamp, interval 1 hour)