JOOQ:如何在复杂的Select语句中使用别名?

时间:2013-10-31 10:25:02

标签: java sql jooq

这是我的选择陈述

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 个答案:

答案 0 :(得分: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");

}