What is the right way to get simple sum
with JOOQ?
SELECT sum(PERSON.AGE) FROM PERSON;
I think about something like that:
BigDecimal sum = factory.select(sum(PERSON.AGE)).from(PERSON).fetch???;
?
Record1<BigDecimal> record = factory.select(sum(PERSON.AGE)).from(PERSON).fetchOne();
BigDecimal decimal = record.getValue(record.field1());
If there are no records to sum, decimal will be null. This case will result in an error if you try ending with:
.fetchOneInto(Integer.class)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With