You are on page 1of 1

--- Question 6.

Write a query to display product_id, product_desc, product_quantity_avail, quantity


sold and show inventory Status of products as below as per below condition:

---- a. For Electronics and Computer categories, if sales till date is Zero then show 'No Sales in past,
give discount to reduce inventory', if inventory quantity is less than 10% of quantity sold,show 'Low
inventory, need to add inventory', if inventory quantity is less than 50% of quantity sold, show
'Medium inventory, need to add some inventory', if inventory quantity is more or equal to 50% of
quantity sold, show 'Sufficient inventory'

select
Pro.PRODUCT_DESC,Prcl.PRODUCT_CLASS_DESC,Pro.PRODUCT_QUANTITY_AVAIL,COUNT(Oitem.PR
ODUCT_QUANTITY) AS

SOLD_QUANTITY,(Pro.PRODUCT_QUANTITY_AVAIL/

(Pro.PRODUCT_QUANTITY_AVAIL+COUNT(Oitem.PRODUCT_QUANTITY))) *100 AS Inv_Qty_Perc,

Case when
(Pro.PRODUCT_QUANTITY_AVAIL/(Pro.PRODUCT_QUANTITY_AVAIL+COUNT(Oitem.PRODUCT_QUA
NTITY))) * 100 < 10

then 'Lowinventory, need to add inventory'

when
(Pro.PRODUCT_QUANTITY_AVAIL/(Pro.PRODUCT_QUANTITY_AVAIL+COUNT(Oitem.PRODUCT_QUA
NTITY))) * 100 < 50

then 'Mediuminventory, need to add some inventory'

when
(Pro.PRODUCT_QUANTITY_AVAIL/(Pro.PRODUCT_QUANTITY_AVAIL+COUNT(Oitem.PRODUCT_QUA
NTITY))) * 100 >= 50

then'Sufficient inventory'Else 'No Sales in past, give discount to reduce inventory'

End AS INVENTORY from product_class Prcl

inner join product Pro on Pro.PRODUCT_CLASS_CODE=Prcl.PRODUCT_CLASS_CODE

inner join order_items Oitem on Oitem.PRODUCT_ID= Pro.PRODUCT_ID

inner join order_header Orhe on Orhe.ORDER_ID=Oitem.ORDER_ID

where Prcl.product_class_desc in ('Electronics','Computer') and


Orhe.ORDER_STATUS='Shipped'group by

Pro.PRODUCT_QUANTITY_AVAIL;

You might also like