我有一个列的表(到期日期)。我想选择今天和下周之间到期的所有行。我使用的是MySQL和InnoDB类型。
我尝试这样的事情:
SELECT name, expiration
FROM exp
WHERE (expiration BETWEEN(CURRENT_DATE, INTERVAL 1 WEEK));
但我的语法不好。有错误:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') LIMIT 0, 30' at line 3
答案 0 :(得分:3)
试试这个:
SELECT *
FROM exp
WHERE expiration BETWEEN
current_date
AND
current_date + interval 7 day
演示: - > http://www.sqlfiddle.com/#!2/8598a/2
答案 1 :(得分:-1)
这应该是您想要的语法:
SELECT name, expiration FROM table WHERE expiration
BETWEEN
CURRENT_DATE
AND
ADDDATE(CURRENT_DATE, INTERVAL 1 WEEK)
(你需要在当前日期添加一周,你不能只指定自己的间隔/作为BETWEEN的参数)