This project contains a relational database schema and a set of analytical SQL queries designed to explore sales performance for an toy car sales business. It focuses on extracting insights such as top-performing products, customer segmentation, and geographic distribution of customers.
.
├── db_setup.sql # Database schema and table creation
└── analysis.sql # Analytical SQL queries
The database is named auto_sales and includes the following tables:
-
Stores categories of products
-
Fields:
product_line_id(PK)product_line
-
Stores individual products
-
Fields:
product_code(PK)product_line_id(FK)msrp
-
Stores customer information
-
Fields include:
customer_id(PK)customer_name- Contact and address details
-
Stores order-level data
-
Fields:
order_number(PK)customer_id(FK)order_datestatus
-
Stores line-item details for each order
-
Fields:
order_item_id(PK)order_number(FK)product_code(FK)quantity_orderedprice_eachsalesdeal_size
The project includes several business-focused SQL queries:
- Identify products generating the most revenue
- Rank products by revenue contribution
- Determine most frequently ordered products
- Analyze total quantity sold per product
- Identify the top 20% of customers by revenue (Pareto principle)
- Rank customers based on spending
- Find countries with the highest number of customers
- Identify top cities by customer count
- Analyze which product lines generate the most revenue
- Rank product lines accordingly
-
Create the database
SOURCE db_setup.sql;
-
Run analysis queries
SOURCE analysis.sql;
-
Used SQL client MySQL Workbench 8.0
- Aggregations (
SUM,COUNT) - Window functions (
RANK,NTILE) - Common Table Expressions (CTEs)
- Joins (INNER, LEFT)
- Data grouping and ranking
- Add sample dataset for testing
- Create dashboards (e.g., Tableau, Power BI)
- Optimize queries for large-scale datasets