我正在尝试使用功能CONCAT和CONCAT_WS在理论上用查询生成器编写sql查询。我的查询如下:
$parameters = [':caseId' => $caseId, ':transOffice' => $transOffice, ':contactsIds:' => $contactsIds];
$results = $this->createQueryBuilder('cc')
->select("CONCAT_WS(', ',
CONCAT('in: ', SUM(CASE WHEN cc.direction = 'in' THEN 1 END)),
CONCAT('out: ', SUM(CASE WHEN cc.direction = 'out' THEN 1 END))
) AS summary")
->addSelect(['ch.name as channel'])
->innerJoin('cc.channel', 'ch')
->where('cc.case = :caseId')
->andWhere('cc.channel IN (1,2)')
->andWhere('cc.office_id = :transOffice')
->andWhere('cc.id IN (:contactsIds)')
->setParameters($parameters)
->groupBy('ch.id')
->addGroupBy('cc.direction')
->getQuery()
->getArrayResult();
return $results;
括号中有错误
在原始sql中非常相似的查询看起来很完美。下面我显示了来自heidiSQL的查询:
我找不到错误原因。我将不胜感激 最好的问候;)