2017-09-28 128 views
0

我想要選擇start_timeend_time之間的所有行。我目前有這個查詢。它工作正常,但一些記錄仍然存在,雖然它不是時間指示的範圍內:MYSQL - 在時間範圍內選擇

結構:

enter image description here

查詢:

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

輸出:

enter image description here

什麼似乎是問題傢伙?

+0

嘗試這種'WHERE'start_time'> = '08:00:00' 和'end_time' <= '09:00:00' ;' –

+0

什麼是柱START_TIME的數據類型和END_TIME –

+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); 
+0

12:30還在那裏。 :( –

+0

@JohnAnthony,編輯答案 – OutOfMind

0

找到了一種方法,以消除不必要的時間。不知道這是否是一種有效的方式,但是因爲它做到了我想要的,所以我覺得這很好。

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

這是工作???????? – iamsankalp89

+0

是的,它的確如此。它做我想要的。 –

+0

好吧,那麼接受爲答案 – iamsankalp89