Miscellaneous
maximum()
Signature
Section titled “Signature”maximum() — returns any
Description
Section titled “Description”Calculates the maximum value for a given property. Uses the SQL function MAX. If no records can be found to perform the calculation on you can use the ifNull argument to decide what should be returned.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
property | string | yes | — | Name of the property to get the highest value for (must be a property of a numeric data type). |
where | string | yes | — | See documentation for findAll. |
include | string | yes | — | See documentation for findAll. |
parameterize | any | yes | true | See documentation for findAll. |
ifNull | any | yes | — | See documentation for average. |
includeSoftDeletes | boolean | yes | false | See documentation for findAll. |
group | string | yes | — | See documentation for findAll. |
Examples
Section titled “Examples”// Get the amount of the highest salary for all employees
highestSalary = model("employee").maximum("salary");
// Get the amount of the highest salary for employees in a given department
highestSalary = model("employee").maximum(property="salary", where="departmentId=##params.key##");
// Make sure a numeric value is always returned, even if no records are found to calculate the maximum for
highestSalary = model("employee").maximum(property="salary", where="salary > ##params.minSalary##", ifNull=0);