我需要你的帮助我如何将下面的Mysql转换成docine。

select * from calendar_data as c where LEAST(c.end, end) - GREATEST(c.start, start) > 0;

我试过这个:
$qb = $em->createQueryBuilder();
$query = $qb->select('items')
                ->from('\Admin\Entity\CalendarData','items')
                ->where('LEAST(items.end, :end) - GREATEST(items.start, :start) > 0')
                ->setParameter('start',$start)
                ->setParameter('end', $end);

(鉴于已经提供了$start$end
我有以下错误:
{
 "type": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
 "title": "Internal Server Error",
 "status": 500,
 "detail": "[Syntax Error] line 0, col 57: Error: Expected known function,   got 'LEAST'"
}

我该怎么做?
这是我的问题生成的sql:
Mysql query to determine if the given datetime is included in the datetime interval

最佳答案

教条中没有最小和最大的功能。您可以重写查询以获得相同的结果或使用ResultSetMapping,如

use Doctrine\ORM\Query\ResultSetMapping;

$start = '';
$end = '';
$rsm = new ResultSetMapping();
$rsm->addEntityResult('CalendarData', 'c');
$rsm->addFieldResult('c', 'id', 'id');
$rsm->addFieldResult('c', 'start', 'start');
$rsm->addFieldResult('c', 'end', 'end');

$query = $this->_em->createNativeQuery('select * from calendar_data where LEAST(c.end, ?) - GREATEST(c.start, ?) > 0;', $rsm);
$query->setParameter(1, $end);
$query->setParameter(2, $start);

$calendarData = $query->getResult();

阅读doctrinehere

关于php - 使用最小和最大函数将SQL转换为 Doctrine ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42803164/

10-11 20:43