Aggregate functions in the query builder APIs

The following methods on the DBFunction class support aggregate queries in the query builder APIs.

Method

Description

Example

Avg

Returns the average of all values in a column

query.compare(DBFunction.Constant(44), GreaterThan.
        DBFunction.Avg(query.getColumnRef("B")))

Count

Returns the number of rows in a column

query.compare(DBFunction.Constant(44), GreaterThan,
        DBFunction.Count(query.getColumnRef("B")))

Min

Returns the minimum value of all values in a column

query.compare(DBFunction.Constant(44), GreaterThan,
        DBFunction.Min(query.getColumnRef("B")))

Max

Returns the maximum value of all values in a column

query.compare(DBFunction.Constant(44), LessThan,
        DBFunction.Max(query.getColumnRef("B")))

Sum

Returns the sum of all values in a column

query.compare(DBFunction.Constant(44), GreaterThan,
       DBFunction.Sum(query.getColumnRef("B")))