pub fn max<ST: SqlOrdAggregate, expr>(
expr: expr,
) -> max<ST, <expr as AsExpression<ST>>::Expression>where
expr: AsExpression<ST>,
Expand description
Represents a SQL MAX
function. This function can only take types which are
ordered.
§Window Function Usage
This function can be used as window function. See WindowExpressionMethods
for details
§Aggregate Function Expression
This function can be used as aggregate expression. See AggregateExpressionMethods
for details.
§Examples
§Normal function usage
assert_eq!(Ok(Some(8)), animals.select(max(legs)).first(connection));
§Window function
let res = animals
.select((name, max(legs).partition_by(id)))
.load::<(Option<String>, Option<i32>)>(connection);
assert_eq!(
Ok(vec![(Some("Jack".into()), Some(4)), (None, Some(8))]),
res
);
§Aggregate function expression
assert_eq!(
Ok(Some(4)),
animals
.select(max(legs).aggregate_filter(legs.lt(8)))
.first(connection)
);