https://github.com/dogan-the-analyst/analyze_data_in_a_model_car_database
This is a SQL project.
https://github.com/dogan-the-analyst/analyze_data_in_a_model_car_database
data-analysis mysql sql
Last synced: over 1 year ago
JSON representation
This is a SQL project.
- Host: GitHub
- URL: https://github.com/dogan-the-analyst/analyze_data_in_a_model_car_database
- Owner: dogan-the-analyst
- Created: 2024-12-22T20:55:22.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-23T09:48:54.000Z (over 1 year ago)
- Last Synced: 2025-01-08T11:56:21.622Z (over 1 year ago)
- Topics: data-analysis, mysql, sql
- Homepage:
- Size: 305 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Analyze Data in a Model Car Database
- The database used in project is `mintclassicsDB.sql` file. I prefered **MySQL Workbench** in this study. So, using the "Import from Self-Contained File" option from the Data Import tool, use the script to create the Mint Classic database on your MySQL Workbench platform.
- You can find SQL queries in the `sql` folder and queries result in the `csv` folder.
- ER Diagram of the db is below.

## First Look at the Project
### Project Scenario
**Mint Classics Company**, a retailer of classic model cars and other vehicles, is looking at closing one of their storage facilities.
To support a data-based business decision, they are looking for suggestions and recommendations for reorganizing or reducing inventory, while still maintaining timely service to their customers. For example, they would like to be able to ship a product to a customer within 24 hours of the order being placed.
### Project Objectives
1. Explore products currently in inventory.
2. Determine important factors that may influence inventory reorganization/reduction.
3. Provide analytic insights and data-driven recommendations.
## SQL Queries to Understand Data and Make Some Conclusions
### 1st Query:
- To see the relationship between warehouse name and stock availability, this SQL query will help. The figure shows that the largest warehouse is `East` and the smallest one is `South`. You can also see that storage percentage of these. In terms of availability `West` seems to be good. On the other hand `North` and `South` are close to full.
```sql
SELECT
w.warehouseCode,
w.warehouseName,
COUNT(p.productCode) AS totalProducts,
SUM(p.quantityInStock) AS totalQuantityInStock,
w.warehousePctCap AS storagePercentage,
FLOOR(SUM(p.quantityInStock) * (100 - w.warehousePctCap) / 100) AS stockAvailability
FROM
products p
LEFT JOIN
warehouses w
ON
w.warehouseCode = p.warehouseCode
GROUP BY
w.warehouseCode,
w.warehouseName
ORDER BY
totalQuantityInStock DESC
;
```

---
### 2nd Query:
- Using this query, I want to find out which warehouses contain which product types, and also how much of each they contain. To summarize: `East` contains only `Classic Cars` while `West` contains only `Vintage Cars`. `North` contains both `Motorcycles` and `Planes`. `South` has by itself three of all product types, namely `Trucks and Buses`, `Ships` and `Trains`.
```sql
SELECT
w.warehouseName,
p.productLine,
SUM(p.quantityInStock) AS totalStock
FROM
products p
LEFT JOIN
warehouses w
ON
w.warehouseCode = p.warehouseCode
GROUP BY
w.warehouseName,
p.productLine
ORDER BY
totalStock DESC
;
```

---
### 3rd Query:
- To find out which type of product is most popular in terms of total quantity ordered, I ran this query. As you can see `Classics Cars` is in first place and `Trains` in last place.
```sql
SELECT
p.productLine,
SUM(od.quantityOrdered) AS totalQuantityOrdered
FROM
orderdetails od
LEFT JOIN
products p
ON
p.productCode = od.productCode
GROUP BY
p.productLine
ORDER BY
totalQuantityOrdered DESC
;
```

---
### 4th Query:
- Most of the orders come from `East`.
```sql
SELECT
w.warehouseCode,
w.warehouseName,
COUNT(od.orderNumber) AS totalOrders,
SUM(od.quantityOrdered) AS totalQuantityOrdered
FROM
warehouses w
JOIN
products p
ON
w.warehouseCode = p.warehouseCode
JOIN
orderdetails od
ON
p.productCode = od.productCode
GROUP BY
w.warehouseCode,
w.warehouseName
ORDER BY
totalQuantityOrdered DESC;
```

---
### 5th Query:
- To answer how many orders come from which country, this query will help us. The USA is by far in first place. The next countries are France, Spain and Australia.
```sql
SELECT
customers.country,
COUNT(customers.country) AS totalOrder
FROM
orders
LEFT JOIN
customers
ON
customers.customerNumber = orders.customerNumber
GROUP BY
customers.country
ORDER BY
totalOrder DESC
;
```

---
### 6th Query:
- Here we can see the most popular product is `192 Ferrari 360 Spider red`, which is located in `East` warehouse.
```sql
SELECT
p.productName,
p.productLine,
p.warehouseCode,
SUM(od.quantityOrdered) AS totalOrdered,
p.quantityInStock
FROM
products p
LEFT JOIN
orderdetails od
ON
p.productCode = od.productCode
GROUP BY
p.productCode,
p.productName
ORDER BY
totalOrdered DESC
;
```

---
### 7th Query:
To answer how many customers live in which country, this query will help us. Customers who are living in USA are by far in first place. The next countries are Germany, France and Spain.
```sql
SELECT
country,
COUNT(customerNumber) AS totalCustomer
FROM
customers
GROUP BY
country
ORDER BY
totalCustomer DESC
;
```

---
### 8th Query:
- I wondered that the difference between the order date and the shipping date, so I wrote this query. The result is devistating because some of the orders, not all, that come from Singapore has 65 days delay of shipping. If you look more closely you can see all of these belongs order number of 10165. You can check the full result in the folder of `csv`.
```sql
SELECT
o.orderNumber,
o.orderDate,
o.shippedDate,
DATEDIFF(o.shippedDate, o.orderDate) AS dateDifference,
p.productLine,
w.warehouseName,
c.country
FROM
orders o
LEFT JOIN
orderdetails od
ON
od.orderNumber = o.orderNumber
LEFT JOIN
products p
ON
p.productCode = od.productCode
LEFT JOIN
warehouses w
ON
w.warehouseCode = p.warehouseCode
LEFT JOIN
customers c
ON
c.customerNumber = o.customerNumber
ORDER BY
dateDifference DESC
;
```

---
### 9th Query:
- Ninth query was made for seeing product shortage in terms of the number of total order and product's quantities in recent stock. Some of the products located in `North` are in first 4 rows.
```sql
SELECT
p.productName,
p.productLine,
p.warehouseCode,
SUM(od.quantityOrdered) AS totalOrdered,
p.quantityInStock
FROM
products p
LEFT JOIN
orderdetails od
ON
p.productCode = od.productCode
GROUP BY
p.productCode,
p.productName
HAVING
totalOrdered > quantityInStock
ORDER BY
totalOrdered DESC
;
```

---
### 10th Query:
- Finally, this query shows us that the amount of some products in the company's inventory are extremely high. These numbers should come down. For example, if you look at the `1995 Honda Civic` which has been ordered 917 times but it's quantity in stock is nearly 11 times higher than the number of it's orders.
```sql
SELECT
p.productName,
p.productLine,
p.warehouseCode,
SUM(od.quantityOrdered) AS totalOrdered,
p.quantityInStock,
ROUND((100 * p.quantityInStock) / SUM(od.quantityOrdered)) AS overStockPercentage
FROM
products p
LEFT JOIN
orderdetails od
ON
p.productCode = od.productCode
GROUP BY
p.productName
ORDER BY
overStockPercentage DESC
;
```

## Recommendations
1. Considering the storage percentages of the warehouses, the company might consider closing the `South` and moving its inventory to the `East`, `North` and `West`.
2. Some of the products are in short supply. For example, `F/A 18 Hornet 1/72` and `1960 BSA Gold Star DBD34`. They should be increased. Otherwise, the difference between the order date and the shipping date would be higher due to supply.
3. First and foremost, the products in the `East` and `North` warehouses should be reduced immediately. They and other products like them represent unnecessary inventory. Such inventory items cause unnecessary costs for the company.
4. The company can open new offices in `Spain` and `Germany`. Due to the results of 5th and 7th queries. `Spain` is the third country with the most orders. And `Germany` is the second country with the most customers.
5. It should be investigated what are the key factors behind the 65 days difference between the order date and the shipping date (order `10165`).