 
        Model Class Statistics Functions any model
Calculates the average value for a given property.
Uses the SQL function AVG.
If no records can be found to perform the calculation on you can use the ifNull argument to decide what should be returned.
| Name | Type | Required | Default | Description | 
|---|---|---|---|---|
| property | string | Yes | Name of the property to calculate the average for. | |
| where | string | No | Maps to the WHEREclause of the query (orHAVINGwhen necessary). The following operators are supported:=,!=,<>,<,<=,>,>=,LIKE,NOT LIKE,IN,NOT IN,IS NULL,IS NOT NULL,AND, andOR(note that the key words need to be written in upper case). You can also use parentheses to group statements. You do not need to specify the table name(s); CFWheels will do that for you. | |
| include | string | No | Associations that should be included in the query using INNERorLEFT OUTERjoins (which join type that is used depends on how the association has been set up in your model). If all included associations are set on the current model, you can specify them in a list (e.g.department,addresses,emails). You can build more complex include strings by using parentheses when the association is set on an included model, likealbum(artist(genre)), for example. These complexincludestrings only work whenreturnAsis set toquerythough. | |
| distinct | boolean | No | false | When true,AVGwill be performed only on each unique instance of a value, regardless of how many times the value occurs. | 
| parameterize | any | No | true | Set to trueto usecfqueryparamon all columns, or pass in a list of property names to usecfqueryparamon those only. | 
| ifNull | any | No | The value returned if no records are found. Common usage is to set this to 0to make sure a numeric value is always returned instead of a blank string. | |
| includeSoftDeletes | boolean | No | false | Set to trueto include soft-deleted records in the queries that this method runs. | 
| group | string | No | Maps to the GROUP BYclause of the query. You do not need to specify the table name(s); CFWheels will do that for you. | 
// Get the average salary for all employees.
avgSalary = model("employee").average("salary");
// Get the average salary for employees in a given department.
avgSalary = model("employee").average(property="salary", where="departmentId=#params.key#");
// Make sure a numeric value is always returned if no records are calculated.
avgSalary = model("employee").average(property="salary", where="salary BETWEEN #params.min# AND #params.max#", ifNull=0);