sum()
Description
Calculates the sum of values for a given property. Uses the SQL function SUM.
Function Syntax
sum(property [, where, include, distinct ])
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
property |
string |
Yes | |
Name of the property to get the sum for (has to be a property of a numeric data type). |
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, SUM returns the sum of unique values only. |
Examples
<!--- Get the sum of all salaries --->
<cfset allSalaries = model("employee").sum(property="salary")>
<!--- Get the sum of all salaries for employees in Australia --->
<cfset allAustralianSalaries = model("employee").sum(property="salary", include="country", where="name='Australia'")>
