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子句中的两个日期,当我这样做时,查询只接受第一次比较?
答案 0 :(得分:0)
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
将选择在pickupdate和ETA之间有所需日期的所有行
<-- 20160804 20160806 -->
pickupdate ETA
如果您只需要选择一个OR秒,请使用OR子句而不是AND。
答案 1 :(得分:-1)
在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)