Advanced_SQL_Assignment_with_Tables
Advanced_SQL_Assignment_with_Tables
Scenario:
You are hired as a data analyst for a company that manages customers, their orders, shipments,
and employee relationships. Your task is to use SQL to extract insights, optimize queries, and
analyze
Table: Customers
Schema:
- first_name: VARCHAR(50)
- last_name: VARCHAR(50)
- age: INT
- country: VARCHAR(50)
Sample Data:
|-------------|------------|------------|-----|---------|
|3 | David | Robinson | 22 | UK |
|4 | John | Reinhardt | 25 | UK |
Schema:
- item: VARCHAR(50)
- amount: DECIMAL(10, 2)
Sample Data:
|----------|------------|---------|-------------|
|1 | Keyboard | 400.00 | 4 |
|2 | Mouse | 300.00 | 4 |
|3 | Monitor | 12000.00 | 3 |
|4 | Keyboard | 400.00 | 1 |
|5 | Mousepad | 250.00 | 2 |
Table: Shippings
Schema:
- status: VARCHAR(50)
Sample Data:
|-------------|------------|----------|
|1 | Pending |2 |
|2 | Pending |4 |
|3 | Delivered | 3 |
|4 | Pending |5 |
|5 | Delivered | 1 |
Table: Employees
Schema:
- name: VARCHAR(50)
- position: VARCHAR(50)
- department: VARCHAR(50)
- salary: DECIMAL(10, 2)
Sample Data:
|-------------|----------|-----------------|------------|--------------|------------|
Assignment Tasks:
1. Data Retrieval Using Joins:
a. Write a query to list all customers and their corresponding order details. Include customers who
b. Create a report showing all employees and their respective managers. Include employees who
2. Combining Queries:
a. Combine the results of customers who have either placed orders or have shipments, avoiding
3. Query Optimization:
a. Write an optimized query to find the total amount of orders placed by each customer. Display
a. Write a query to create a hierarchy of employees, showing their name, position, and their
manager's name.
a. Simulate a FULL OUTER JOIN between the Customers and Orders tables and retrieve all
records.
6. Advanced Challenge:
- Customer Name.
- A column indicating if the customer is a High-Value Customer (total order amount > 10,000).
Submission Guidelines:
1. Save all queries in a .sql file with comments explaining the logic for each query.
2. Test your queries against the dataset and ensure they produce correct results.