0% found this document useful (0 votes)
68 views15 pages

SQL Project

Uploaded by

Arpita Mishra
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
68 views15 pages

SQL Project

Uploaded by

Arpita Mishra
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 15

Structured Query Language Project

on
“Reliant Retail Limited”

Table of Contents

1
1 Project Objective…………………………………………………………………………………………………. 3
2 Entity Relationship Diagram………………………………………………………………………………… 3
3 1st part(Q1-Q6) executes in DB Browser……………………………………………………………… 4
4 2nd part(Q7-Q10) executed in MySQL…………………………………………………………………... 10
5 Reference…………………………………………………………………………………………………………….. 15

2
1. Project Objective
The objective of this project is to retrieve data from the database “orders” that will help the
company in making data driven decisions that will impact the overall growth of the online
retail store.

2. Entity Relationship Diagram

3
3. 1st part(Q1-Q6) executes in DB Browser.

1. Write a query to Display the product details (product_class_code, product_id, product_desc,


product_price,) as per the following criteria and sort them in descending order of category:

a. If the category is 2050, increase the price by 2000


b. If the category is 2051, increase the price by 500
c. If the category is 2052, increase the price by 600.

4
Solution:

Result:

- 60 records displayed based on the criteria given and sorted in descending order.
- For Product Code 2050, Product price is increased by 2000.
- For Product Code 2051, Product Price is increased by 500 and
- For Product Code 2052, Product price is increased by 600.

2. Write a query to display (product_class_desc, product_id, product_desc,


product_quantity_avail ) and Show inventory status of products as below as per their
available quantity:

a. For Electronics and Computer categories, if available quantity is <= 10, show 'Low stock',
11 <= qty <= 30, show 'In stock', >= 31, show 'Enough stock'

5
b. For Stationery and Clothes categories, if qty <= 20, show 'Low stock', 21 <= qty <= 80,
show 'In stock', >= 81, show 'Enough stock'
c. Rest of the categories, if qty <= 15 – 'Low Stock', 16 <= qty <= 50 – 'In Stock', >= 51 –
'Enough stock'

For all categories, if available quantity is 0, show 'Out of stock'.

Solution:

Result:

- First find the Product Code for ‘Electronics’, ‘Computer’, ‘Stationery’ and ‘Clothes’ from
Product_Class table.
- The next query used nested CASE to accommodate multiple conditions.
- Retrieve ‘Product_Class_Desc’ from Product_class table and ‘Product_ID’, ‘Product_Desc’
and ‘Product_Quantity_Avail’ from Product table.
- Used alias pc forProduct_Class table and p for Product table.

6
3. Write a query to Show the count of cities in all countries other than USA & MALAYSIA, with
more than 1 city, in the descending order of CITIES. (2 rows) [NOTE: ADDRESS TABLE, Do not
use Distinct].

Solution:

Result:

7
4. Write a query to display the customer_id, customer full name , city, pincode, and order
details (order id, order date, product class desc, product desc, subtotal(product_quantity *
product_price)) for orders shipped to cities whose pin codes do not have any 0s in them.
Sort the output on customer name, order date and subtotal.
(52 ROWS)
[NOTE: TABLE TO BE USED - online_customer, address, order_header, order_items,
product, product_class]

Solution:

Result:

- Calculated value of Product Price and quantity which displayed in Sub Total field.
- Join the Address table with Address ID field to fetch the City and Pincode details.
- Join Order Header table with Customer ID field to fetch Order ID.
- Join Order Items table with Order ID field to fetch Product Quantity.
- Join Product table with Product ID field to fetch Product Description and Product Price
- Join Product Class table with Product Class Code field to fetch Product class description.
- Filter the data which by ‘shipped’ and Pin code which does not have value ‘0’.
- Order by customer name and subtotal.
- Order Date field has no values.
- 52 records retrieved.

8
5. Write a Query to display product id, product description, total quantity(sum(product
quantity) for an item which has been bought maximum no. of times along with product id
201. (USE SUB-QUERY) (1 ROW)
[NOTE: ORDER_ITEMS TABLE, PRODUCT TABLE]

Solution:

Result:

- Join table Order Item with Product Table by Product ID field to fetch the Product description.
- Calculating sum of Product Quantity.
- Using nested select statement in Where clause to pull out all the orders that have the
product_id 201 and ‘AND’ statement is used to make sure that Product ID should not be 201.
- Total quantity(sum(product quantity) for each product_id that was brought most number of
times along with product_id 201.
- Sort by Total_Quantity on descending
- Show the first row

9
6. Write a query to display the customer_id, customer name, email and order details (order id,
product desc, product qty, subtotal (product_quantity * product_price)) for all customers
even if they have not ordered any item.(225 ROWS)
[NOTE: TABLE TO BE USED - online_customer, order_header, order_items, product]

Solution:

Result:

- 255 records are returned.


- Joined Online Customer with Order Header to fetch Order ID and
- Join Order Items table by Order_ID field to fetch Product quantity field.
- Join Product table by Product ID field to fetch Product description and Product Price field.
- Calculated Total Price as Subtotal

4. 2nd part(Q7-Q10) executes in MySQL.

Below queries are executed in MySQL:

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). (1 ROW)
[NOTE: CARTON TABLE, PRODUCT TABLE]

10
Solution:

Result:

- Nested select query is used to calculate volume details from both Order_items and Product
tables using inner join, conditioned by Order ID = 10006, which gives output 980552700.
- Output of nested query is used as a condition for outer select query to find the least volume
whose volume is greater than output of nested select query.
- 01 record retrieved in result.
- Limit 1 is used to retrieve first row

11
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,]

Solution:

Result:-

- Retrieved Customer ID, Customer Name for Online Customer table.


- Joining Order Items table to fetch Product Quantity field and calculating the sum of Product
Quantity where order status id ‘Shipped’.
- Joining Online_Order table with Customer Header to fetch Order ID field.
- The condition is used as Order_status which is ‘Shipped’.
- Grouped by Order ID that has quantity more than 10. This is used to further put condition to
select those field that has quantity greater than 10.

12
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]

Solution:

Result:
- 6 records retrieved from the query.
- Retrieved Order ID from joining Order Header table, Product Quantity from joining Order
Itmes table and Customer ID and Customer names from Online Customer table.
- Joining Last name and First Name using concat function.
- Condition is placed in where clause for order status to be ‘shipped’ and order ID > 10060.

13
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]

Solution:

Result:
- Condition given is Order status to be ‘shipped’ and any county other than India and USA.
- Joined Order header table to find Order status.
- Joined Online Customer table to further joining Address table to retrieve Country field.
- Order status as Shipped & country without India and USA.
- Result displays Product class code, Product Class Description, Sum of Product quantity as per
conditions and Total value of Product quantity and Product Price.

5. References:

14
Reference used for completion of this project:

1. Great Learning recorded videos.


2. https://www.w3schools.com/sql/sql_case.asp
3. https://documentation.sisense.com/latest/managing-data/transforming-data/
sql-reference.htm#gsc.tab=0

15

You might also like