我有这样的查询:
SELECT * FROM bcl1_logs where created_at between '2015-02-07' and '2015-02-10'
和这样的表:
0 = "id":1,
"pc_name":"BCL101",
"created_at":"2015-02-07 22:25:44"
2 = "id":2,
"pc_name":"BCL101",
"created_at":"2015-02-07 22:25:44"
3 = "id":3,
"pc_name":"BCL101",
"created_at":"2015-02-10 22:25:44"
当我查询我的陈述时,它只显示前两行' 2014-02-07'日期,它不包括“2015-02-10'当我的查询是BETWEEN日期' 2014-02-07'和' 2015-02-10'。
答案 0 :(得分:0)
在查询中添加时间
SELECT * FROM bcl1_logs where created_at between '2015-02-07 00:00:00' and '2015-02-10 23:59:59'
答案 1 :(得分:0)
如果您只使用日期部分,则时间部分设置为00:00:00
。所以你的查询看起来像是
created_at between '2015-02-07 00:00:00' and '2015-02-10 00:00:00'
并且不包括时间为22:25:44
的第三条记录。
更改为:
created_at between '2015-02-07 00:00:00' and '2015-02-10 23:59:59'
答案 2 :(得分:0)
value between X and Y
表示value >= x AND value < y
,因此遗漏了'2015-02-10'
。如果您想使用between
运算符并将其包含在内,则需要再添加一天:
SELECT *
FROM bcl1_logs
WHERE created_at BETWEEN '2015-02-07' AND '2015-02-11'
答案 3 :(得分:0)
其他答案解释了您将日期与日期和时间进行比较的问题,因此请尝试在查询中使用DATE()
:
SELECT * FROM bcl1_logs WHERE DATE(created_at) BETWEEN '2015-02-07' AND '2015-02-10'