1-use orders;
select* from ONLINE_CUSTOMER;
select concat(case CUSTOMER_GENDER
when 'M' then 'Mr.'
when 'F' then 'Ms.'
end ,' ',upper(CUSTOMER_FNAME),' ' ,upper(CUSTOMER_LNAME)) as
CUSTOMER_FULL_NAME, CUSTOMER_EMAIL, CUSTOMER_CREATION_DATE,
case
when year(CUSTOMER_CREATION_DATE)<2005 then 'A'
when 2005<=year(CUSTOMER_CREATION_DATE) and year(CUSTOMER_CREATION_DATE)<2011
then 'B' else 'C'
end as CUSTOMERS_CATEGORY from online_customer;
2-
select * from ORDER_ITEMS;
select PRODUCT_ID, PRODUCT_DESC, PRODUCT_QUANTITY_AVAIL, PRODUCT_PRICE,
(PRODUCT_QUANTITY_AVAIL*PRODUCT_PRICE) as INVENTORY_VALUES,
case
when PRODUCT_PRICE > 20000 then (PRODUCT_PRICE*20)/100
when PRODUCT_PRICE>10000 then (PRODUCT_PRICE*15)/100
when PRODUCT_PRICE <= 10000 then (PRODUCT_PRICE*10)/100
end as NEW_PRICE from PRODUCT
order by INVENTORY_VALUES DESC;
3-
SELECT*FROM PRODUCT;
SELECT*FROM PRODUCT_CLASS;
select P.PRODUCT_CLASS_CODE, PC.PRODUCT_CLASS_DESC,
(P.PRODUCT_QUANTITY_AVAIL*P.PRODUCT_PRICE )AS INVENTORY_VALUE,
count(PRODUCT_CLASS_DESC) as COUNT_PRODUCT_TYPE
from PRODUCT P
inner join PRODUCT_CLASS PC
ON P.PRODUCT_CLASS_CODE = PC.PRODUCT_CLASS_CODE
where (P.PRODUCT_QUANTITY_AVAIL*P.PRODUCT_PRICE) > 100000
group by PRODUCT_CLASS_DESC
order by INVENTORY_VALUE desc;
4-
select OC.CUSTOMER_ID, concat(upper(OC.CUSTOMER_FNAME),' ',upper(OC.CUSTOMER_LNAME))
FULL_NAME ,OC.CUSTOMER_EMAIL,OC.CUSTOMER_PHONE,A.COUNTRY
from ONLINE_CUSTOMER OC
inner join ADDRESS A
using (ADDRESS_ID)
inner join ORDER_HEADER
using (CUSTOMER_ID)
where ORDER_STATUS = 'Cancelled';
5-
select B.SHIPPER_NAME, B.CITY, Count(Distinct A.CUSTOMER_ID) CUSTOMER_COUN from
ORDER_HEADER A,
(select A.SHIPPER_NAME, A.SHIPPER_ID, B.City, B.ADDRESS_ID from SHIPPER A, ADDRESS B
where A.SHIPPER_ADDRESS = B.ADDRESS_ID and A.SHIPPER_NAME = 'DHL') B
where A.SHIPPER_ID = B.SHIPPER_ID
Group by B.SHIPPER_NAME,B.City;
7-
select * from carton;
WITH ORDER_VOLUME as
(SELECT ORDER_ITEMS.ORDER_ID, (PRODUCT.LEN * PRODUCT.WIDTH * PRODUCT.HEIGHT) VOLUME
FROM ORDER_ITEMS
JOIN PRODUCT ON PRODUCT.PRODUCT_ID = ORDER_ITEMS.PRODUCT_ID), carton_10_volume as
(SELECT(CARTON.LEN * CARTON.WIDTH * CARTON.HEIGHT) CARTON_10_VOLUME FROM CARTON
WHERE CARTON_ID = 10)
SELECT ORDER_VOLUME.ORDER_ID, ORDER_VOLUME.VOLUME FROM
ORDER_VOLUME,carton_10_volume
WHERE ORDER_VOLUME.VOLUME <= carton_10_volume.CARTON_10_VOLUME
ORDER BY ORDER_VOLUME.VOLUME DESC
limit 1;
6-
select * from ORDER_ITEMS;
select* from ORDER_HEADER;
select OC.CUSTOMER_ID,concat(OC.CUSTOMER_FNAME,' ',OC.CUSTOMER_LNAME) as FULL_NAME,
count(OI.PRODUCT_QUANTITY) as TOTAL_QUANTITY,
sum(OI.PRODUCT_QUANTITY * P.PRODUCT_PRICE) as TOTAL_VALUE from ONLINE_CUSTOMER OC
inner join ORDER_HEADER OH
using (CUSTOMER_ID)
inner join ORDER_ITEMS OI
using(ORDER_ID)
inner join PRODUCT P
using (PRODUCT_ID)
where ORDER_STATUS = 'Shipped' and payment_mode='Cash' and CUSTOMER_LNAME like 'G%'
group by CUSTOMER_ID;
9-
select P.PRODUCT_ID, P.PRODUCT_DESC,A.CITY,Count(OI.PRODUCT_QUANTITY) as Total_Quantity
from PRODUCT P
inner join ORDER_ITEMS OI
on OI.PRODUCT_ID = P.PRODUCT_ID
inner join ORDER_HEADER OH
on OH.ORDER_ID = OI.ORDER_ID
inner join ONLINE_CUSTOMER OC on OC.CUSTOMER_ID = OH.CUSTOMER_ID
inner join ADDRESS A on A.ADDRESS_ID= OC.ADDRESS_ID
where P.PRODUCT_ID = OI.PRODUCT_ID and P.PRODUCT_ID = 201 and A.CITY not in
('Bangalore','New Delhi')
Group by P.PRODUCT_ID, P.PRODUCT_DESC,A.CITY;
10-
select OI.ORDER_ID, OC.CUSTOMER_ID, concat(OC.CUSTOMER_FNAME,' ',OC.CUSTOMER_LNAME) as
FULL_NAME, sum(OI.PRODUCT_QUANTITY) as TOTAL_QUANTITY from ORDER_ITEMS OI
inner join ORDER_HEADER OH
using (ORDER_ID)
inner join ONLINE_CUSTOMER OC
using (CUSTOMER_ID)
inner join ADDRESS A
using (ADDRESS_ID)
where ORDER_ID%2=0 and pincode not like '5%'
group by ORDER_ID;
8-
select P.PRODUCT_DESC,PC.PRODUCT_CLASS_DESC,P.PRODUCT_QUANTITY_AVAIL,
COUNT(OI.PRODUCT_QUANTITY) AS SOLD_QUANTITY,
(P.PRODUCT_QUANTITY_AVAIL/(P.PRODUCT_QUANTITY_AVAIL+COUNT(OI.PRODUCT_QUANTITY)))
*100 AS AVAILABLE_QTY_PRC,
Case
when (P.PRODUCT_QUANTITY_AVAIL/
(P.PRODUCT_QUANTITY_AVAIL+COUNT(OI.PRODUCT_QUANTITY)))* 100 < 10
then 'Lowinventory, need to add inventory'
when (P.PRODUCT_QUANTITY_AVAIL/
(P.PRODUCT_QUANTITY_AVAIL+COUNT(OI.PRODUCT_QUANTITY)))* 100 < 50
then 'Mediuminventory, need to add some inventory'
when (P.PRODUCT_QUANTITY_AVAIL/
(P.PRODUCT_QUANTITY_AVAIL+COUNT(OI.PRODUCT_QUANTITY)))* 100 >= 50 then'Sufficient
inventory'
Else 'No Sales in past, give discount to reduce inventory'
End AS INVENTORY_STATUS from product_class PC
inner join product P
on P.PRODUCT_CLASS_CODE=PC.PRODUCT_CLASS_CODE
inner join order_items OI
on OI.PRODUCT_ID= P.PRODUCT_ID
inner join order_header OH
on OH.ORDER_ID=OI.ORDER_ID
where PC.product_class_desc in ('Electronics','Computer')
and OH.ORDER_STATUS='Shipped'
group by P.PRODUCT_QUANTITY_AVAIL;
b-
select P.PRODUCT_DESC,PC.PRODUCT_CLASS_DESC,P.PRODUCT_QUANTITY_AVAIL,
COUNT(OI.PRODUCT_QUANTITY) AS SOLD_QUANTITY,
(P.PRODUCT_QUANTITY_AVAIL/(P.PRODUCT_QUANTITY_AVAIL+COUNT(OI.PRODUCT_QUANTITY)))
*100 AS AVAILABLE_QTY_PRC,
Case
when (P.PRODUCT_QUANTITY_AVAIL/
(P.PRODUCT_QUANTITY_AVAIL+COUNT(OI.PRODUCT_QUANTITY)))* 100 < 20
then 'Lowinventory, need to add inventory'
when (P.PRODUCT_QUANTITY_AVAIL/
(P.PRODUCT_QUANTITY_AVAIL+COUNT(OI.PRODUCT_QUANTITY)))* 100 < 60
then 'Mediuminventory, need to add some inventory'
when (P.PRODUCT_QUANTITY_AVAIL/
(P.PRODUCT_QUANTITY_AVAIL+COUNT(OI.PRODUCT_QUANTITY)))* 100 >= 60
then'Sufficient inventory' Else 'No Sales in past, give discount to reduce inventory'
End AS INVENTORY_STATUS from product_class PC
inner join product P
on P.PRODUCT_CLASS_CODE=PC.PRODUCT_CLASS_CODE
inner join order_items OI
on OI.PRODUCT_ID= P.PRODUCT_ID
inner join order_header OH
on OH.ORDER_ID=OI.ORDER_ID
where PC.product_class_desc in ('Electronics','Computer') and OH.ORDER_STATUS='Shipped'
group by P.PRODUCT_QUANTITY_AVAIL;
c-
select P.PRODUCT_DESC,PC.PRODUCT_CLASS_DESC,P.PRODUCT_QUANTITY_AVAIL,
COUNT(OI.PRODUCT_QUANTITY) AS SOLD_QUANTITY,
(P.PRODUCT_QUANTITY_AVAIL/(P.PRODUCT_QUANTITY_AVAIL+COUNT(OI.PRODUCT_QUANTITY)))
*100 AS AVAILABLE_QTY_PRC,
Case
when (P.PRODUCT_QUANTITY_AVAIL/
(P.PRODUCT_QUANTITY_AVAIL+COUNT(OI.PRODUCT_QUANTITY)))* 100 < 30
then 'Lowinventory, need to add inventory'
when (P.PRODUCT_QUANTITY_AVAIL/
(P.PRODUCT_QUANTITY_AVAIL+COUNT(OI.PRODUCT_QUANTITY)))* 100 < 70
then 'Mediuminventory, need to add some inventory'
when (P.PRODUCT_QUANTITY_AVAIL/
(P.PRODUCT_QUANTITY_AVAIL+COUNT(OI.PRODUCT_QUANTITY)))* 100 >= 70
then'Sufficient inventory'
Else 'No Sales in past, give discount to reduce inventory'
End AS INVENTORY_STATUS
from product_class PC
inner join product P
on P.PRODUCT_CLASS_CODE=PC.PRODUCT_CLASS_CODE
inner join order_items OI
on OI.PRODUCT_ID= P.PRODUCT_ID
inner join order_header OH
on OH.ORDER_ID=OI.ORDER_ID
where PC.product_class_desc in ('Electronics','Computer')
and OH.ORDER_STATUS='Shipped'
group by P.PRODUCT_QUANTITY_AVAIL;