doctor,使用count和concat进行查询

bqjvbblv  于 2021-06-15  发布在  Mysql
关注(0)|答案(0)|浏览(298)

我在条令中用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

但在查询生成器中,我有语法问题。我应该如何在查询生成器中正确地编写这个查询?我将非常感谢你的帮助。致以最诚挚的问候

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题