7

is there any option to set alias for $qb->expr()->avg('e.value') in select() method of Doctrine2 query builder?

I have e.g. this query:

$qb->select($qb->expr()->avg('e.value'), 'e someAlias')->from('Entity', 'e');

But the average value is indexed by integer in the result, like this:

array(
  0 => array(
   'someAlias' => Entity {},
   1 => 2.5255,
  ),
);

Is it possible to change key of the average value to the defined string value?

1 Answer 1

8

Try the following to set the alias:

$qb->select(array(
                 $qb->expr()->select()->avg('e.value').' AS aveAlias')
                ,'e someAlias')
           )->from('Entity', 'e');
0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.