2016-07-30 9 views
-3
select truckid 
from truck_log 
where '20160804' between ruck_log.pickupdate and truck_log.ETA 
    and '20160806' between truck_log.pickupdate and truck_log.ETA 

두 날짜를 비교할 때 where 절을 비교할 때 쿼리가 첫 번째 비교 만 받아들이는 경우?SQL에서 where 절에 여러 날짜를 비교하는 방법

+3

어떤 DBMS를 사용하고 있습니까? –

+1

'쿼리가 첫 번째 비교 만 받아들이는 것을 의미합니까? ' –

+0

'AND' 또는'OR' 둘 중 하나를 사용해야합니다. – NEER

답변

-1

추가하는 대신 WHERE 절에 "AND"의 "OR"

검색어 :

select truckid from truck_log 

where ('20160804' between truck_log.pickupdate and truck_log.ETA) 

     or ('20160806' between truck_log.pickupdate and truck_log.ETA) 
0

오타 ruck_log되고 Truck_log을해야 하는가?

true의 경우, 대신의 하나 또는 두 번째, 사용 또는 절을 선택해야하는 경우이

select truckid 
from truck_log 
where '20160804' between truck_log.pickupdate and truck_log.ETA 
    and '20160806' between truck_log.pickupdate and truck_log.ETA 

이 pickupdate 및 ETA

  <-- 20160804 20160806 --> 
pickupdate       ETA 

사이에 날짜를 필요한 모든 행을 선택합니다 과.

관련 문제