Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Is there way to set up the alias name for the "AVG" column in the QueryBuilder?

Hello.

Is there way to set up the alias name for the AVG column in the QueryBuilder?

I can not find answer in the docs, please help.



83.4k
Accepted
answer

You can pass an associative array using the keys as aliases:

$builder->columns(["average" => "avg(price)"])


25.4k

Thank you for the reply! I think it's should be in the documentation, here: http://docs.phalconphp.com/en/latest/reference/phql.html#creating-queries-using-the-query-builder



5.4k

You can also write:

$builder->columns('avg(price) AS average')

(Or are there advantages to using the array format?)