我有一个查询,该查询是使用Doctrine中的queryBuilder构建的:
$results = $this->createQueryBuilder('cc')
->select("CONCAT('in: ', COUNT(CASE WHEN cc.direction = 'in' THEN 1 END),', out:', COUNT(CASE WHEN cc.direction = 'out' THEN 1 END)) AS summary")
->addSelect(['ch.name as channelName'])
->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();
主要问题在于函数:COUNT和CONCAT。没有此选择,它将起作用,但没有效果。我收到响应错误:
非常相似的原始sql效果很好:
select Count(*) as number_of_contacts, channel_id, CONCAT('in: ', COUNT(CASE WHEN direction = 'in' THEN 1 END),', out:', COUNT(CASE WHEN direction = 'out' THEN 1 END)) AS summary from cic_case_contacts where case_id = 328678 group By channel_id
ORDER BY channel_id
但是在查询生成器中我有语法问题。 我应该如何在查询生成器中正确编写此查询? 我将不胜感激。 最好的问候