Subodh Joshi
Subodh Joshi

Reputation: 13492

JOOQ:How to use alias in complex Select statement?

Here is my select statement

SelectQuery<Record> selectQueryPayment = transaction.selectQuery();
    selectQueryPayment.addSelect(AccountPayment.ACCOUNT_PAYMENT.PAYMENT_NUMBER,AccountPayment.ACCOUNT_PAYMENT.PAYMENT_AMOUNT,AccountPayment.ACCOUNT_PAYMENT.PAYMENT_TYPE,
                     AccountPayment.ACCOUNT_PAYMENT.PAYMENT_DATE,AccountPayment.ACCOUNT_PAYMENT.PAYMENT_AMOUNT,AccountPayment.ACCOUNT_PAYMENT.PAYMENT_AMOUNT.subtract(AccountPayment.ACCOUNT_PAYMENT.AMOUNT_REFUNDED.add(AccountPayment.ACCOUNT_PAYMENT.AMOUNT_APPLIED)));

Here you can see a complex select with some calculation

ACCOUNT_PAYMENT.PAYMENT_AMOUNT.subtract(AccountPayment.ACCOUNT_PAYMENT.AMOUNT_REFUNDED.add(AccountPayment.ACCOUNT_PAYMENT.AMOUNT_APPLIED))

How to create Alias for this? And then get back data from it?

Upvotes: 0

Views: 601

Answers (1)

Subodh Joshi
Subodh Joshi

Reputation: 13492

Ok I got the solution we can use this

AccountPayment.ACCOUNT_PAYMENT.PAYMENT_AMOUNT.subtract(AccountPayment.ACCOUNT_PAYMENT.AMOUNT_REFUNDED.add(AccountPayment.ACCOUNT_PAYMENT.AMOUNT_APPLIED)).as("OverPayment")

We have to add as("Alias Name") and getting value back we have to use

     Result<Record> resultPayment = selectQueryPayment.fetch();
           for(Record record : resultPayment){
           feeAmount =  resultPayment.getValues("OverPayment");

}

Upvotes: 1

Related Questions