처음에는 각 공급 업체가 각 고객에게 (배포자를 통해 간접적으로) 수행 한 총 달러 비즈니스의 내역을보고자했습니다. 여기에서 내부 조인 구문을 사용하지 않으려 고 시도하고 있습니다. 이 목적을 위해 아래 쿼리 :하위 쿼리 이해
select customers.cust_id, Vendors.vend_id, sum(quantity*item_price) as total_business from
(((Vendors left outer join Products
on Products.vend_id = Vendors.vend_id)
left outer join OrderItems --No inner joins allowed
on OrderItems.prod_id = Products.prod_id)
left outer join Orders
on Orders.order_num = OrderItems.order_num)
left outer join Customers
on Customers.cust_id = Orders.cust_id
where Customers.cust_id is not null -- THE ONLY DIFFERENCE BETWEEN QUERY1 AND QUERY2
group by Customers.cust_id, Vendors.vend_id
order by total_business
을 지금, 나는 거래에는 비즈니스 없었다 그 조합을 포함하여 모든 공급 업체 고객 조합에 대한 쿼리의 출력 결과를 확인하기 위해 노력하고 단일 SQL을 통해이 쓰기 위해 노력하고 있어요 질문. 저의 선생님은이 솔루션을 제공해 주셨지만 솔직히 말해서 서브 쿼리를 사용 해본 적이 없어서 논리를 전혀 이해할 수 없습니다.
select
customers.cust_id,
Vendors.vend_id,
sum(OrderItems.quantity*orderitems.item_price)
from
(
customers
inner join
Vendors on 1 = 1
)
left outer join --synthetic product using joins
(
orders
join
orderitems on orders.order_num = OrderItems.order_num
join
Products on orderitems.prod_id = products.prod_id
) on
Vendors.vend_id = Products.vend_id and
customers.cust_id = orders.cust_id
group by customers.cust_id, vendors.vend_id
order by customers.cust_id
덕분에 많은