MYSQL - 在时间范围之间选择

时间:2017-09-28 04:47:32

标签: mysql time

我想选择start_timeend_time之间的所有行。我目前有这个查询。它工作正常但有些记录仍然存在,尽管它不在指定的时间范围内:

结构:

enter image description here

查询:

SELECT * FROM `tbl_subloading` 
WHERE`start_time` >= '08:00AM' and `end_time`<= '09:00AM';

输出:

enter image description here

什么似乎是问题家伙?

2 个答案:

答案 0 :(得分:0)

试试这个:

SELECT * FROM `tbl_subloading` 
WHERE`start_time` between CAST('08:00:00' AS time) and 
CAST('09:00:00' AS time) and `end_time` between 
CAST('08:00:00' AS time) and CAST('09:00:00' AS time);

答案 1 :(得分:0)

找到消除不必要时间的方法。不知道这是否是一种有效的方式,但由于它做了我想要的,我认为这一切都很好。

SELECT * FROM `tbl_subloading` 
WHERE `start_time` BETWEEN '08:00AM' and '09:00PM' 
and `end_time` BETWEEN '08:00AM' and '09:00PM'