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?
Try the following to set the alias:
$qb->select(array(
$qb->expr()->select()->avg('e.value').' AS aveAlias')
,'e someAlias')
)->from('Entity', 'e');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With