Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get simple Sum with JOOQ? [duplicate]

Tags:

java

sql

sum

jooq

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???;

?

like image 554
Mark Avatar asked Oct 15 '25 03:10

Mark


1 Answers

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)
like image 132
Jag Avatar answered Oct 18 '25 02:10

Jag