我的表中的列的类型为timestamp,我在数据库1中有2条记录,其值为#34; 2014-07-12 23:10:15"和#34; 2013-06-01 01:10:12"
现在查询表,但我的结果是空的:
SELECT comments.* FROM tbl_product_comments as comments WHERE DATE(comments.created_date) BETWEEN 2010-06-01 AND 2014-07-13
也是这样,但又一次得到空结果
SELECT comments.* FROM tbl_product_comments as comments WHERE DATE(comments.created_date) > 2010-06-01 AND DATE(comments.created_date) < 2014-07-13
任何人都可以告诉我,为什么我没有得到结果以及什么是正确的查询。
谢谢..
答案 0 :(得分:3)
用引号括起你的日期文字。
BETWEEN '2010-06-01' AND '2014-07-13'
您的原始代码被解析为算术表达式。
2010-06-01 = 2003
2014-07-13 = 1994
实施例。这将返回数据:
select * from tab where 2009 between 2010-01-01 and 2014-01-01
评估为
select * from tab where 2009 between 2008 and 2012