Mysql 如何选择比一周更新的行?
使用MariaDB 10,我想查询过去一周文章的Mysql 如何选择比一周更新的行?,mysql,sql,mariadb,intervals,Mysql,Sql,Mariadb,Intervals,使用MariaDB 10,我想查询过去一周文章的article表: 我的问题是: SELECT * FROM article WHERE category="News" AND created_at < NOW() - INTERVAL 1 WEEK ORDER BY created_at DESC; 如何实现这一点?逻辑是反向的。您想要的是而不是 +-------------+-----------------+------+-----+-------------------+----
article
表:
我的问题是:
SELECT * FROM article WHERE category="News" AND created_at < NOW() - INTERVAL 1 WEEK ORDER BY created_at DESC;
如何实现这一点?逻辑是反向的。您想要的是
而不是
+-------------+-----------------+------+-----+-------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-----------------+------+-----+-------------------+----------------+
| id | int(6) unsigned | NO | PRI | NULL | auto_increment |
| title | varchar(150) | NO | | NULL | |
| content | mediumtext | NO | | NULL | |
| created_at | timestamp | NO | | CURRENT_TIMESTAMP | |
| category | varchar(64) | NO | | test | |
SELECT a.*
FROM article a
WHERE category = 'News' AND
created_at > NOW() - INTERVAL 1 WEEK
ORDER BY created_at DESC;