Professional Documents
Culture Documents
IF EXISTS orders;
use orders;
DROP TABLE IF EXISTS ORDER_ITEMS;
DROP TABLE IF EXISTS CARTON;
DROP TABLE IF EXISTS ORDER_HEADER;
DROP TABLE IF EXISTS ONLINE_CUSTOMER;
DROP TABLE IF EXISTS SHIPPER;
DROP TABLE IF EXISTS ADDRESS;
DROP TABLE IF EXISTS PRODUCT;
DROP TABLE IF EXISTS PRODUCT_CLASS;
#-------------------------------------------------------
#-- 7Q. Write a query to display carton id, (len*width*height) as carton_vol
and identify the optimum carton
#-- (carton with the least volume whose volume is greater than the total volume
of all items
#-- (len * width * height * product_quantity)) for a given order whose order id
is 10006, Assume all items of an
#-- order are packed into one single carton (box). (1 ROW) [NOTE: CARTON TABLE]
#-------------------------------------------------------
#--7Ans:
select CARTON_ID, cart.LEN * cart.WIDTH * cart.HEIGHT as CARTON_VAL from
`carton` cart
where CARTON_ID * cart.LEN * cart.WIDTH * cart.HEIGHT >
(Select sum(prod.`LEN` * prod.`WIDTH` * prod.`HEIGHT` * orit.`PRODUCT_QUANTITY`)
from `order_items` orit
inner join `product` prod where orit.`ORDER_ID` = 10006);
#-------------------------------------------------------
#-- 8. Write a query to display details (customer id,customer fullname,order
id,product quantity) of customers
#-- who bought more than ten (i.e. total order qty) products per shipped order.
(11 ROWS) [NOTE: TABLES TO BE USED -
#-- online_customer, order_header, order_items,]
#-------------------------------------------------------
#-- 8Ans:
select oncu.customer_id, oncu.customer_fname, orhe.order_id,
sum(orit.PRODUCT_QUANTITY)
from online_customer oncu
join order_header orhe on orhe.`CUSTOMER_ID` = oncu.`CUSTOMER_ID`
left join order_items orit on orhe.`ORDER_ID` = orit.`ORDER_ID`
where orhe.`ORDER_STATUS` = 'Shipped'
group by orhe.order_id
having sum(PRODUCT_QUANTITY) > 10;
#-------------------------------------------------------
#-- 9. Write a query to display the order_id, customer id and cutomer full name
of customers along with (product_quantity)
#-- as total quantity of products shipped for order ids > 10060. (6 ROWS) [NOTE:
TABLES TO BE USED - online_customer,
#-- order_header, order_items]
#-------------------------------------------------------
#-- 9Ans:
select oncu.`CUSTOMER_ID`, oncu.`CUSTOMER_FNAME`, orhe.`ORDER_ID`,
orit.`PRODUCT_QUANTITY` from `online_customer` oncu
inner join `order_header` orhe on oncu.`CUSTOMER_ID` = orhe.`CUSTOMER_ID`
inner join `order_items` orit on orhe.`ORDER_ID` = orit.`ORDER_ID`
where orhe.`ORDER_STATUS` = 'Shipped'
group by orhe.`ORDER_ID`
having orhe.`ORDER_ID` > '10060'
order by orhe.`ORDER_ID`;
#-------------------------------------------------------
#-- 10. Write a query to display product class description ,total quantity
(sum(product_quantity),Total value
#-- (product_quantity * product price) and show which class of products have
been shipped highest(Quantity) to
#-- countries outside India other than USA? Also show the total value of those
items. (1 ROWS)[NOTE:PRODUCT TABLE,
#-- ADDRESS TABLE,ONLINE_CUSTOMER TABLE,ORDER_HEADER TABLE,ORDER_ITEMS
TABLE,PRODUCT_CLASS TABLE]
#-------------------------------------------------------
#-- 10Ans:
select prodc.`PRODUCT_CLASS_DESC`, sum(orit.`PRODUCT_QUANTITY`) as
TOTAL_QUANTITY,
orit.`PRODUCT_QUANTITY` * prod.`PRODUCT_PRICE` as TOTAL_VALUE,
addr.`COUNTRY`
from ONLINE_CUSTOMER as oncu
inner join `address` addr ON oncu.ADDRESS_ID = addr.ADDRESS_ID
inner join `order_header` orhe on oncu.`CUSTOMER_ID` = orhe.`CUSTOMER_ID`
inner join `order_items` orit on orhe.`ORDER_ID` = orit.`ORDER_ID`
inner join `product` prod ON prod.PRODUCT_ID = orit.PRODUCT_ID
inner join `product_class` prodc ON prod.PRODUCT_CLASS_CODE =
prodc.PRODUCT_CLASS_CODE
where addr.`COUNTRY` != 'India' and addr.`COUNTRY` != 'USA' and
orhe.`ORDER_STATUS` = 'Shipped'
group by orhe.`ORDER_STATUS`;