Doctrine orm 教义2&;Symfony2一次查询中的多个计数

Doctrine orm 教义2&;Symfony2一次查询中的多个计数,doctrine-orm,symfony,Doctrine Orm,Symfony,我想就symfony2和条令提出如下请求: SELECT (SELECT count(id) FROM table1) AS c1, (SELECT count(id) FROM table2) AS c2, (SELECT count(id) FROM table3) AS c3, (SELECT count(id) FROM table4) AS c4 (注意:此请求在mysql中工作) 但是我不知道如何用教义来做, 我试过这样的方法: $em = $this->getDoctri

我想就symfony2和条令提出如下请求:

SELECT 
(SELECT count(id) FROM table1) AS c1,
(SELECT count(id) FROM table2) AS c2,
(SELECT count(id) FROM table3) AS c3,
(SELECT count(id) FROM table4) AS c4
(注意:此请求在mysql中工作) 但是我不知道如何用教义来做, 我试过这样的方法:

$em = $this->getDoctrine()->getEntityManager();
$result = $em->createQuery('SELECT
    (SELECT count(id) FROM MyBundle:Table1) AS c1,
    (SELECT count(id) FROM MyBundle:Table2) AS c2,
    (SELECT count(id) FROM MyBundle:Table3) AS c3,
    (SELECT count(id) FROM MyBundle:Table4) AS c4'
)->getResult();
然而,它引发了一个例外:

("[Semantical Error] line 0, col 144 near ') AS c2,
': Error: ')' is already defined.") in 
那么,有可能做我想做的事情吗?如果有,怎么做


任何帮助都将不胜感激:)

此错误是因为
$em->createQuery($dql)
您只能使用(条令查询语言)

如果要在查询中使用SQL,必须使用
$em->getConnection()->fetchAssoc($SQL)

希望这对你有帮助