Lecture 5: Real-world Practice with Northwind
Querying an unknown database, optimization & best practices
This work is licensed under CC BY-NC-SA 4.0
© Way-Up 2025
For this session, work with a MySQL-compatible tool
mysql -u root -p




SELECT * FROM categories c
-- 1. list of customers
-- 2. number of different products?
-- 3. count of employees
-- 4. total overall revenue
-- 5. total revenue for one specific year
-- 6. list of countries covered by delivery
-- 7. list of available transporters
-- 8. number of customer per countries
-- 9. number of orders which are "ordered" but not shipped
-- 10. all the orders from france and belgium
-- 11. most expensive products
-- 12. list of discontinued products
-- 13. count of product per category
-- 14. average order price
-- 15. revenue per category
-- 16. number of orders per shipper
-- 17. number of orders per employee
-- 18. total revenue per supplier
-- 19. top 5 customers by total order value
-- 20. list all products that have never been ordered
-- 21. average order value per employee
-- 22. products with stock below reorder level
-- 23. customers who haven't placed orders in 1997
-- 24. list of employees with their manager names
-- 25. most profitable product (highest total revenue)
-- 26. average delivery time (shipped_date - order_date) per shipper
-- 27. products that are out of stock (units_in_stock = 0)
-- 28. total quantity sold per product
-- 29. customers with the most orders
-- 30. revenue breakdown by year and quarter
-- 31. insert a product with its category
-- 32. create an order (what is required?)
-- 33. change the shipped delivery date
-- 34. add a new customer
-- 35. create an order with multiple order details
-- Example: Create a view
CREATE VIEW customer_orders_summary AS
SELECT
c.customer_id,
c.company_name,
COUNT(o.order_id) as total_orders,
SUM(od.unit_price * od.quantity) as total_spent
FROM customers c
LEFT JOIN orders o ON c.customer_id = o.customer_id
LEFT JOIN order_details od ON o.order_id = od.order_id
GROUP BY c.customer_id, c.company_name;
Analyze and optimize the following query:
-- Before optimization
SELECT * FROM orders o
JOIN order_details od ON o.order_id = od.order_id
JOIN products p ON od.product_id = p.product_id
WHERE YEAR(o.order_date) = 1997;
Tasks:
Create a comprehensive sales report showing:
Requirements: