我想创建一个Doctrine查询:(Doctrine 2.3)
SELECT * FROM `car` WHERE `plate` like '%' AND (`datetime` BETWEEN '2013-03-13 22:20:18' AND '2013-03-13 22:20:20') OR (`datetime` BETWEEN '2013-03-13 15:10:18' AND '2013-03-13 15:10:16')
我尝试了下面这个方法,但是没有生效:
$qry = $this->manager()->createQueryBuilder()
->from($this->entity, 'e')
->select('e');
$qry->where('e.plate like :plate');
$qry->setParameter('plate', $plate);
$qry->andWhere(
qry->expr()->between(
'e.datetime',
':dateFrom',
':dateTo'
)
)
->setParameter('dateFrom', $fromdate)
->setParameter('dateTo', $todate);
$qry->orWhere(
$qry->expr()->between(
'e.datetime',
':dateFrom',
':dateTo'
)
)
->setParameter('dateFrom1', $fromdate1)
->setParameter('dateTo1', $todate1);
上述查询的输出结果为:
SELECT e FROM user e WHERE (e.plate like :plate AND (e.datetime BETWEEN :dateFrom AND :dateTo)) OR (e.datetime BETWEEN :dateFrom AND :dateTo)
我想检查同一列中的两个日期,应该如何检查?这个语法正确吗? 目前是这样的:
(Plate AND (Date)) OR Date)
案例1
但是为了获得良好的输出效果,应该按照以下方式进行。
(Plate) AND ((Date) OR (Date))
案例2
在其他情况下,应该是这样的:
((Plate) or (Plate)) AND ((Date) OR (Date))
有人能帮我吗?我不是Doctrine的专家,我正在学习中!