我试图在mysql中选择两个日期属性之间的记录,但是我正在尝试的查询不起作用,可能是因为date属性不是字符串所以它无法比较它!
这是我试过的查询。
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
答案 0 :(得分: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)
我不认为你真的想要那个。