2014-12-15 1 views
-1

내가 몇 테이블이 찾을 하위 쿼리 - 청구서, Invc_tender 및 Invc_fee 여기경우 다른 값

에게 내가 무엇을하고자하는 경우입니다

SELECT so.so_no, c.first_name, c.last_name, c.cust_id, i.invc_no, i.created_date, it.amt, i.invc_type, it.tender_type, it.crd_type, ife.fee_type 
     FROM rpro.invoice i 
     LEFT JOIN rpro.so so ON so.so_sid = i.so_sid 
     LEFT JOIN rpro.invc_tender it ON it.invc_sid = i.invc_sid 
     LEFT JOIN rpro.invc_fee ife ON ife.invc_sid = i.invc_sid 
     LEFT JOIN rpro.customer c ON c.cust_sid = i.cust_sid 
     WHERE i.invc_type IN (0,2) AND ife.fee_type != -2 AND i.created_date >= '2014-12-10' AND i.store_no = 0 

내 현재 쿼리입니다 ii.tender_type 찾아 it.tender_type, it.crd_type 초기 쿼리 결과에 실제 값을 전달하는 다음 쿼리를 수행 7과 동일하고, 하나 개의 탭에 관해서

SELECT it.tender_type, it.crd_type, it.amt 
     FROM rpro.so so 
     LEFT JOIN rpro.invoice i ON i.so_sid = so.so_sid 
     LEFT JOIN rpro.invc_tender it ON it.invc_sid = i.invc_sid 
     LEFT JOIN rpro.invc_fee ife ON ife.invc_sid = i.invc_sid 
     WHERE ife.fee_type = -2 AND so.so_sid = (The SO_SID of the current invoice result) 
     ORDER BY i.created_date desc 

을 it.amt 레 관계. SO 테이블은 Invoice와 일대 다 관계를 갖고 Invoice는 Invc_tender와 Invc_fee와 일대 다 관계를 맺습니다. 기본적으로 현재 송장을 보는 대신 ii.tender_type = 7 인 경우 ife.fee_type = -2

인이 SO에 첨부 된 다른 송장을 찾으십시오.이 작업은 하나의 쿼리 또는 중첩 쿼리에서 가능 했습니까? 아니면 여러 쿼리를 수행해야 할 것이 었습니까?

+0

1. WHERE를 AND로 변경하십시오. – Strawberry

답변

1

필요한 SO_SID를 반환하는 하위 쿼리 사용