我有一张名为ticket的表。但是,我试图在两个日期之间进行查询;我一直收到语法错误。任何帮助都会对这种语法错误有所了解。
SELECT date
FROM ticket
WHERE date BETWEEN YEAR(ticket.date)=2011 AND MONTH(ticket.date)=11 AND DAY(ticket.date)=06
AND YEAR(ticket.date)=2011 AND MONTH(ticket.date)=11 AND DAY(ticket.date)=12
您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在'= 2011和MONTH(ticket.date)= 11 AND DAY(ticket.date)= 06 AND YEAR(ticket.date)= 20'附近使用正确的语法1
答案 0 :(得分:4)
date BETWEEN YEAR(ticket.date)=2011
没有任何意义。语法是
date BETWEEN start_range AND end_range
所以大概是
date BETWEEN '2011-11-06' AND '2011-11-12'
或者你有一个时间组件,你应该避免使用BETWEEN
,只需使用
date >= '2011-11-06' AND date < '2011-11-13'
答案 1 :(得分:1)
这是一个不正确的BETWEEN
条款:
BETWEEN YEAR(ticket.date)=2011
应该看起来像:
BETWEEN YEAR(ticket.date) AND 2011
答案 2 :(得分:0)
我认为我们会做到这一点:
"SELECT
date
FROM
ticket
WHERE
date BETWEEN '2011-11-06' AND 2011-11-12'"
你不应该像你一样使用BETWEEN。你正在评估你的(我的)sql不支持它。
答案 3 :(得分:0)
试试这个:
SELECT date
FROM ticket
WHERE DAY(ticket.date) BETWEEN 6 AND 12
AND MONTH(ticket.date) = 11
AND YEAR(ticket.date) = 2011
答案 4 :(得分:0)
您无法在between
中列出多个值。
将查询重写为:
SELECT date
FROM ticket
WHERE date BETWEEN '2011-11-06' and '2011-11-12'