Skip to content

Miscellaneous

maximum()

maximum() — returns any

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.

NameTypeRequiredDefaultDescription
propertystringyesName of the property to get the highest value for (must be a property of a numeric data type).
wherestringyesSee documentation for findAll.
includestringyesSee documentation for findAll.
parameterizeanyyestrueSee documentation for findAll.
ifNullanyyesSee documentation for average.
includeSoftDeletesbooleanyesfalseSee documentation for findAll.
groupstringyesSee documentation for findAll.
// 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);