You are on page 1of 1

--- Question 9.

Write a query to display product_id, product_desc and total quantity of products


which are sold together with product id 201 and are not shipped to city Bangalore and New Delhi.
Display the output in descending order with respect to the tot_qty. -- (USE SUB-QUERY) -- [NOTE:
TABLES to be used - order_items, product,order_header, online_customer, address]

select pro.PRODUCT_ID,pro.PRODUCT_DESC,sum(ol.PRODUCT_QUANTITY) as total_quantity

from product pro

join order_items ol on pro.PRODUCT_ID=ol.PRODUCT_ID

join order_header ohl on ol.ORDER_ID=ohl.ORDER_ID

join online_customer ocl on ohl.CUSTOMER_ID=ocl.CUSTOMER_ID

join address ad on ocl.ADDRESS_ID=ad.ADDRESS_ID

where ol.ORDER_ID in (select ol.ORDER_ID from order_items where PRODUCT_ID='201' and

ohl.ORDER_STATUS='shipped' and ad.CITY not in ('Bangalore','New Delhi') )

group by pro.PRODUCT_ID,pro.PRODUCT_DESC

order by total_quantity desc;

You might also like