我有一个准备好的语句,需要在cakephp 1.3中使用find()查询它。我该怎么做。我尝试了不同的条件但没有成功。这是我准备好的陈述
"select v.id from vehicles as v left join trips t on (v.id=t.vehicle_id) where t.departure_date between '2012-10-31 10:41:30' AND '2012-11-06 10:41:38' and t.id is null"
感谢。
答案 0 :(得分:0)
我不认为这个sql语句会返回任何结果,因为你在某些值之间说t.departure_date然后说t.id IS NULL(除非t.id在表中实际上可以是NULL)。据推测,你想要这样的东西:
select v.id
from vehicles as v
left join trips t on v.id=t.vehicle_id
AND t.departure_date between '2012-10-31 10:41:30'
AND '2012-11-06 10:41:38'
WHERE t.id is null
这将返回出发日期中旅行表中不存在的任何车辆ID。就php方面而言,不确定我是否可以提供帮助。
希望这有帮助。