Aggregate Functions

dodikuswono1 | 3 years ago

I tried Recess almost one month. But i don't have any idea how to use SQL aggregate functions.

Anybody can help?



KrisJordan | 3 years ago

There is a method named 'selectAs' on Models that allows you to do an aggregate operation.

ex: $modelsWithDistance = $model->all()->selectAs('ABS(someIntColumn - 5)', 'distance')

Now when you iterate over the results of $modelsWithDistance there should be a new property 'distance' that contains the aggregate field.

This should cover your scenario, but if not let us know.

reply



Welcome KrisJordan!

Web: http://www.krisjordan.com/

Location: North Carolina

Edit Profile