Professional Documents
Culture Documents
Untitled
Untitled
SQL Project
You are hired by a chain of online retail stores “Reliant retail limited”. They provided you with
“orders” database and seek answers
to the following queries as the results from these queries will help the company in making data-
driven decisions that will impact the
/*
product_price) as per the following criteria and sort them descending order of category:
*/
case
else p.product_price
end as product_price
from product p
This study source was downloaded by 100000860386075 from CourseHero.com on 04-17-2023 01:56:20 GMT -05:00
https://www.coursehero.com/file/199530867/SQL-Projectdocx/
/*
a. For Electronics and Computer categories, if available quantity is <= 10, show 'Low stock', 11 <= qty
<= 30,
b. For Stationery and Clothes categories, if qty <= 20, show 'Low stock', 21 <= qty <= 80, show 'In
stock', >=81,
c. Rest of the categories, if qty <= 15 – 'Low Stock', 16 <= qty <= 50 – 'In Stock', >= 51 – 'Enough stock'
stock'.
*/
case
end as inventory_status
This study source was downloaded by 100000860386075 from CourseHero.com on 04-17-2023 01:56:20 GMT -05:00
https://www.coursehero.com/file/199530867/SQL-Projectdocx/
from product p left join product_class pr
on p.product_class_code = pr.product_class_code;
/*
3. Write a query to Show the count of cities in all countries other than USA & MALAYSIA, with
*/
select country, count(city) as number_city from address where country not in ('USA', 'MALAYSIA')
group by country having number_city>1;
/*
product_price)) for orders shipped to cities whose pin codes do not have any 0s in them.
*/
select oc.customer_id,
concat(oc.customer_fname,oc.customer_lname) as fullname,
a.city,
a.pincode,
oh.order_id,
pc.product_class_desc,
p.product_desc,
(p.product_price*oi.product_quantity) as subtotal
address a on oc.address_id=a.address_id
This study source was downloaded by 100000860386075 from CourseHero.com on 04-17-2023 01:56:20 GMT -05:00
https://www.coursehero.com/file/199530867/SQL-Projectdocx/
left join product p on oi.product_id=p.product_id)
order by fullname,oh.order_date,subtotal ;
/*
given item whose product id is 201 and which item has been bought along with it maximum no. of
times. Display only one record which has the maximum value for total quantity in this scenario.
*/
from ((order_items a
join (select distinct order_id from order_items where product_id = 201) b on (a.order_id =
b.order_id))
group by a.product_id
limit 1)
select oi.product_id,
p.product_desc,
sum(oi.product_quantity) as totalquantity,
where oi.product_id=201
group by oi.product_id,p.product_desc ;
This study source was downloaded by 100000860386075 from CourseHero.com on 04-17-2023 01:56:20 GMT -05:00
https://www.coursehero.com/file/199530867/SQL-Projectdocx/
/* 6. Write a query to display the customer_id,customer name, email and order details
select oc.customer_id,
concat(oc.customer_fname,oc.customer_lname) as fullname,
oc.customer_email,
oh.order_id,
p.product_desc,
oi.product_quantity,
(oi.product_quantity*p.product_price) as subtotal
from (((online_customer oc
/*7. 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) */
p.len,
p.width,
p.height,
(p.len*p.width*p.height) as volume_of_item
from order_items o
where order_id=10006
group by order_id),
This study source was downloaded by 100000860386075 from CourseHero.com on 04-17-2023 01:56:20 GMT -05:00
https://www.coursehero.com/file/199530867/SQL-Projectdocx/
CARTONS AS (select c.carton_id,
(c.len*c.width*c.height) as carton_vol
from carton c
SELECT CARTONS.CARTON_ID,
CARTONS.CARTON_VOL,
FROM CARTONS
/*
of customers who bought more than ten (i.e. total order qty) products with credit card or net
SELECT
OH.CUSTOMER_ID,
oh.order_id,
concat(oc.customer_fname,oc.customer_lname) as fullname,
sum(OI.PRODUCT_quantity) as quantityordered
FROM ORDER_HEADER OH
group by OH.CUSTOMER_ID,fullname
having quantityordered>10;
/* 9.Write a query to display the order_id,customer_id and customer fullname starting with “A” along
This study source was downloaded by 100000860386075 from CourseHero.com on 04-17-2023 01:56:20 GMT -05:00
https://www.coursehero.com/file/199530867/SQL-Projectdocx/
with (product quantity) as total quantity of products shipped for order ids > 10030
select OH.CUSTOMER_ID,
oh.order_id,
concat(oc.customer_fname,oc.customer_lname) as fullname,
sum(OI.PRODUCT_quantity) as total_quantity_of_products_shipped
from order_header oh
where oh.order_id>10030
group by OH.CUSTOMER_ID,oh.order_id,fullname
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. */
select pc.product_class_desc,
sum(oi.product_quantity),
ad.country
group by pc.product_class_desc,ad.country
This study source was downloaded by 100000860386075 from CourseHero.com on 04-17-2023 01:56:20 GMT -05:00
https://www.coursehero.com/file/199530867/SQL-Projectdocx/
ORDER BY TOTAL_VALUE DESC
/* Furniture is the highest sold product class and Malaysia is the highest importer. */
This study source was downloaded by 100000860386075 from CourseHero.com on 04-17-2023 01:56:20 GMT -05:00
https://www.coursehero.com/file/199530867/SQL-Projectdocx/
Powered by TCPDF (www.tcpdf.org)