这是我的MySQL查询。
SELECT Timestamp,a_number,Verdict,OrderId
FROM Main
WHERE Timestamp between DATE '2014-03-12' AND '2014-03-11'
and a_location like '%london%';
在上面的查询中,Timestamp是Main表中的一个字段。但是当我执行查询时,它正在执行并将输出作为空集。
当我检查存储在数据库中的Timestamp值时,我得到下面给出的值
1323517427743,1323867674980。
我做错了什么。我应该做些什么来改变我的需要。
答案 0 :(得分:2)
col BETWEEN a AND b
是col >= a AND col <= n
以上的语法糖 - 也就是说,您必须使用正确的顺序:
SELECT Timestamp,a_number,Verdict,OrderId
FROM Main
WHERE Timestamp between DATE '2014-03-11' AND '2014-03-12'
AND a_location like '%london%';
答案 1 :(得分:0)
尝试在DATE列周围使用后退标记
SELECT Timestamp,a_number,Verdict,OrderId
FROM Main
WHERE Timestamp between `DATE` '2014-03-12' AND '2014-03-11'
and a_location like '%london%';
答案 2 :(得分:0)
如果Timestamp
的列类型为timestamp
,那么您可以这样做:
SELECT `Timestamp`, a_number,Verdict,OrderId
FROM Main
WHERE `Timestamp` between '2014-03-11' AND '2014-03-12'
and a_location like '%london%';
如果是整数,那么你应该这样做:
SELECT `Timestamp`, a_number,Verdict,OrderId
FROM Main
WHERE `Timestamp` between UNIX_TIMESTAMP('2014-03-11') AND UNIX_TIMESTAMP('2014-03-12')
and a_location like '%london%';
对于between A and B
,A
应小于或等于B
,否则不会返回任何结果。