如何比较 sql 中 where 子句中的多个日期

how to compare multiple dates in where clause in sql

 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 子句中的两个日期,查询只接受第一个比较?

在 where 子句中添加“OR”而不是“AND”:

查询:

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)

ruck_log 是错字吗,应该是 Truck_log

如果为真,这

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

将select所有要求日期介于取件日期和预计到达时间之间的行

          <-- 20160804   20160806 -->
pickupdate                           ETA  

如果您只需要 select 一个或第二个,请使用 OR 子句而不是 AND。