average()
Description
Calculates the average value for a given property. Uses the SQL function AVG.
Function Syntax
average(property [, where, include, distinct ])
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
property |
string |
Yes | |
Name of the property to calculate the average for. |
where |
string |
No | |
An SQL fragment such as lastName LIKE 'A%' for example. |
include |
string |
No | |
Any associations that need to be included in the query. |
distinct |
boolean |
No | false |
When true, AVG will be performed only on each unique instance of a value, regardless of how many times the value occurs. |
Examples
<!--- Get the average salary for all employees --->
<cfset avgSalary = model("employee").average("salary")>
