具有CONCAT和CONCAT_WS函数的学说SQL查询

时间:2019-03-21 14:05:24

标签: mysql sql doctrine concat query-builder

我正在尝试使用功能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;

括号中有错误

enter image description here

在原始sql中非常相似的查询看起来很完美。下面我显示了来自heidiSQL的查询:

enter image description here

我找不到错误原因。我将不胜感激 最好的问候;)

0 个答案:

没有答案