0
SELECT t1.field1 AS foo, (SELECT ABS(SUM(amount)) FROM table2 t2) FROM table1;

How can I convert this query into symfony 2 doctrine query builder?

$results = $this->getEntityManager()->createQueryBuilder()
           ->select(...)
           //...

1 Answer 1

3
$results = $this->getEntityManager()->createQueryBuilder()
  ->select('t1.field1')
  ->addSelect('abs(sum(amount)) t2')
  ->from('BundleName:Entity', 't1)
  ->leftJoin('t1.field', 'another')
  ->getQuery()->getResult();

Maybe this works, I found a similar problem and a solution here: Select Subquery with COUNT() in Doctrine DQL

Or if it not works, you can create two queries for the problem, and you use the first query's result in the second query.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.