KevsRobots Learning Platform
By Kevin McAleer, 5 Minutes
In this lesson, we’ll review the key topics covered in this course and introduce a final project that lets you apply everything you’ve learned to a real-world scenario.
Over the past lessons, you’ve built a strong foundation in SQL, covering the following key concepts:
SELECT, INSERT, UPDATE, DELETE).WHERE, ORDER BY, and LIMIT to refine and organize query results.AND, OR, and CASE statements for dynamic filtering.GROUP BY with aggregate functions (SUM, COUNT, AVG, MIN, MAX) to summarize data.For this project, you’ll create a small database to manage sales data for a fictional company. This database will allow you to track customers, products, orders, and sales, applying the concepts and skills you’ve developed throughout the course.
Your database should include the following tables:
customer_id: Unique identifier for each customer (PRIMARY KEY)name: Customer’s nameemail: Customer’s email (ensure it’s unique)join_date: Date the customer joinedproduct_id: Unique identifier for each product (PRIMARY KEY)product_name: Name of the productprice: Price of the productorder_id: Unique identifier for each order (PRIMARY KEY)customer_id: ID of the customer who placed the order (FOREIGN KEY referencing customers)order_date: Date the order was placedorder_item_id: Unique identifier for each item in an order (PRIMARY KEY)order_id: ID of the associated order (FOREIGN KEY referencing orders)product_id: ID of the product ordered (FOREIGN KEY referencing products)quantity: Number of items orderedtotal_price: Calculated as quantity * pricePopulate each table with sample data to test your queries. Include at least:
order_itemsUse the following questions as prompts to write SQL queries and test your understanding:
SELECT * FROM customers
WHERE join_date > DATE_SUB(NOW(), INTERVAL 1 YEAR);
SELECT * FROM products
WHERE price > 50;
SELECT p.product_name, SUM(oi.total_price) AS total_sales
FROM order_items AS oi
JOIN products AS p ON oi.product_id = p.product_id
GROUP BY p.product_name;
SELECT c.name, COUNT(o.order_id) AS order_count
FROM customers AS c
JOIN orders AS o ON c.customer_id = o.customer_id
GROUP BY c.customer_id
HAVING order_count > 1;
SELECT o.order_id, c.name, p.product_name, oi.quantity, oi.total_price
FROM orders AS o
JOIN order_items AS oi ON o.order_id = oi.order_id
JOIN customers AS c ON o.customer_id = c.customer_id
JOIN products AS p ON oi.product_id = p.product_id
WHERE p.product_name = 'Laptop';
SELECT SUM(total_price) AS total_revenue
FROM order_items;
customer_orders that shows each customer’s name, order ID, and order date.
CREATE VIEW customer_orders AS
SELECT c.name, o.order_id, o.order_date
FROM customers AS c
JOIN orders AS o ON c.customer_id = o.customer_id;
order_date column in the orders table to improve the performance of date-based queries.
CREATE INDEX idx_order_date ON orders (order_date);
If you’re ready for a challenge, try adding more complex requirements to your project:
discount field in the order_items table, then calculate total_price to reflect the discount.categories table and link products to categories, then write queries to analyze sales by category.Congratulations on completing the course! By now, you should have a solid foundation in SQL and relational database theory. You can:
This final project has helped you apply your skills to a practical scenario. Keep practicing, experiment with new datasets, and continue building on the concepts you’ve learned. SQL is a valuable skill that will serve you well across many projects and applications.
Thank you for participating in this course, and good luck with your SQL journey!
You can use the arrows ← → on your keyboard to navigate between lessons.
Comments