We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
DbAssist supports the aggregate SQL functions by implementing the following methods inside AbstractRepository.
AbstractRepository
count
avg
sum
sumAsLong
sumAsDouble
min
max
least
greatest
The rest of the article shows how to use the selected methods. A few examples show also how to add conditions on the query.
The count method returns Long object.
ConditionsBuilder c = new ConditionsBuilder(); HierarchyCondition hc = c.equal("name", "Mont"); c.apply(hc); Long count = uRepo.count(c);
Result:
SELECT COUNT(id) FROM users WHERE name = 'Mont'
The sum method returns whatever type is returned as a result of SQL query. For example Integer for INT database type, and Double for DOUBLE type.
ConditionsBuilder c = new ConditionsBuilder(); HierarchyCondition hc = c.lessThan("salary", 10000.0); c.apply(hc); Long count = uRepo.sum(c, "id");
SELECT SUM(id) FROM users WHERE salary < 10000.0
The avg method returns Double as a result of SQL query.
Double avg = uRepo.avg(new ConditionsBuilder(), "salary");
SELECT AVG(salary) FROM users