0

我正在尝试在mysql中选择两个日期属性之间的记录,但是我尝试的查询不起作用,可能是因为日期属性不是字符串所以它无法比较它!

这是我尝试过的查询。

SELECT * 
FROM object, object_info
WHERE oi_object = o_id
AND o_category =  '6'
AND o_address =  'Gostivar'
AND o_status =  'approved'
AND o_available_from >= date(2013-08-15)
AND o_available_to <= date(2013-08-31)
ORDER BY o_date DESC 
4

1 回答 1

0

您需要将日期值括在单引号中:

SELECT * 
FROM object, object_info
WHERE oi_object = o_id
AND o_category =  '6'
AND o_address =  'Gostivar'
AND o_status =  'approved'
AND o_available_from >= date('2013-08-15')
AND o_available_to <= date('2013-08-31')
ORDER BY o_date DESC ;

您的查询实际上是在做:

AND o_available_from >= date(2013 - 08 - 15)
AND o_available_to <= date(2013 - 08 - 31)

这是

AND o_available_from >= date(1980)
AND o_available_to <= date(1974)

我不认为你真的想要那样。

于 2013-08-11T17:21:35.317 回答