2013-10-31 67 views
0

這裏是我的select語句JOOQ:如何在複雜的Select語句中使用別名?

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

在這裏你可以看到一個複雜的一些計算

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

如何爲這個創建別名選擇?然後從中獲取數據?

回答

1

好我得到了我們可以利用這個

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

我們必須添加as("Alias Name")並獲得價值回,我們必須使用

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

}

解決方案