2017-11-04 17 views
1

숙제를 다하고 있는데이 문제를 파악하지 못했습니다. 누구든지 제발 도와 주실 래요? 이 Oracle SqlCorrelated Subquery, oracle sql

공급 업체의 평균 송장 금액보다 높은 각 송장 금액을 표시하십시오. 상관 하위 쿼리를 사용해야합니다.

나는 시도했지만 그만큼 가까이 있지 않습니다. 여기 내 코드는 다음과 같습니다 https://i.stack.imgur.com/w9D6i.png

답변

2

가 외부 쿼리 테이블의 별칭을 사용하고 vendor_id 필드의 상관 관계 :

SELECT vendor_id, invoice_number, invoice_total 
FROM ap.invoices 
WHERE invoice_total > (SELECT AVG(invoice_total) 
        FROM ap.invoices 
        where invoice_id=invoice_id 
        ) 
ORDER BY vendor_id; 

결과 테이블이 이미지와 일치해야합니다

SELECT vendor_id, invoice_number, invoice_total 
FROM ap.invoices i 
WHERE invoice_total > (
    SELECT AVG(invoice_total) 
    FROM ap.invoices v 
    where v.vendor_id = i.vendor_id 
) 
ORDER BY vendor_id; 
+0

방탄복을, 당신 그 남자 야! 고마워. –