The following Doctrine DQL query returns a syntax error :
return $this->getEntityManager()->createQuery(
'SELECT i invoice, (
(SELECT SUM(p1.amount) FROM PaymentTableA p1 WHERE p1.invoice = i.id)
+
(SELECT SUM(p2.amount) FROM PaymentTable2 p2 WHERE p2.invoice = i.id)
) mySUM
FROM Invoice i
WHERE i.id BETWEEN 1 AND 50'
)->getResult();
I would like a "simple" sum of 2 sub queries like this valid MySQL statement
select i.*, (
(select sum(p1.amount) from PaymentTable1 p1 where p1.invoice_id = i.id)
+
(select sum(p2.amount) from PaymentTable2 p2 where p2.invoice_id = i.id)
) mySUM
from Invoice i
where i.id between 1 and 50;
How can I do this with DQL?