Aggregate functions

Aggregate functions perform a calculation on a set of values and return a single value. Except for COUNT, aggregate functions ignore null values. Aggregate functions are frequently used with the GROUP BY clause of the SELECT statement.

ReActiveAndroid supports following aggregate functions:

COUNT - returns the number of rows returned by the query.

AVG - returns the average of the values in a group.

MIN - returns the maximum value in the expression.

MAX - returns the minimum value in the expression.

SUM - returns the sum of all the values.

TOTAL - returns the sum of all the values.

GROUP_CONCAT - returns a string which is the concatenation of all non-NULL values.

More detailed information about aggregate functions can be found here.

To call aggregete functions just start build expression like a regular Select-query, , but instead of fetch() -method, call _a _method with the same name as the aggregate function:

Select.from(Note.class).count();
Select.from(Note.class).avg(columnName);
Select.from(Note.class).min(<columnName);
Select.from(Note.class).max(columnName);
Select.from(Note.class).sumA(columnName);
Select.from(Note.class).total(columnName);
Select.from(Note.class).groupConcat(columnName);

Asynchronous execution

You can also call aggregate functions asynchronously:

Select.from(Note.class).countAsync();
Select.from(Note.class).avgAsync(columnName);
Select.from(Note.class).minAsync(<columnName);
Select.from(Note.class).maxAsync(columnName);
Select.from(Note.class).sumAsync(columnName);
Select.from(Note.class).totalAsync(columnName);
Select.from(Note.class).groupConcatAsync(columnName);

All these methods return Single class from RxJava 2.

results matching ""

    No results matching ""