2013-12-09 1 views
0

JOOQ에서 SelfJoin을 사용할 수 있습니까?Jooq에서 SelfJoin을 사용하는 방법?

Select Count(1) CountPayments 
From PaymentDetail APD1, PaymentDetail APD2, Payment AP 
where APD1.PaymentNumber =123 
    and APD1.BillNumber > 0 
    and APD2.BillNumber = APD1.BillNumber 
    and APD2.PaymentNumber <> APD1.PaymentNumber 
    and AP.PaymentNumber = APD2.PaymentNumber 

그렇다면 어떻게 위의 쿼리에서 사용할 수 있습니까?

답변

1

The manual's section about aliasing tables 몇 가지 실마리를 줄 수 있습니다.

본질적으로, 당신의 테이블에 별칭을 할당합니다

PaymentDetail APD1 = PaymentDetail.as("APD1"); 
PaymentDetail APD2 = PaymentDetail.as("APD2"); 
Payment AP = Payment.as("AP"); 

DSL.using(configuration) 
    .select(count(1).as("CountPayments")) 
    .from(APD1, APD2, AP) 
    .where(APD1.PaymentNumber.eq(123)) 
    .and(APD1.BillNumber.gt(0)) 
    .and(APD2.BillNumber.eq(APD1.BillNumber)) 
    .and(APD2.PaymentNumber.ne(APD1.PaymentNumber)) 
    .and(AP.PaymentNumber.eq(APD2.PaymentNumber))