The Northwind database is a sample database that was originally created by Microsoft and used as the basis for their tutorials in a variety of database products. The database contains the sales data for a fictitious company called 'Northwind Traders', which imports and exports specialty foods from around the world. The Northwind is an excellent tutorial schema for a small-business ERP, with customers, orders, inventory, purchasing, suppliers, shipping, employees, and single-entry accounting.
I created this sample Northwind Database for beginners who want learn about MySQL from W3Schools. Since I work with MySQL, so I modify the syntax accordingly. I work with MySQL version 8.0.27.
There are several differences:
- in W3Schools, CustomerID column in Customers table uses
SMALLINT
as datatype, but here I useCHAR(5)
following the original database. - there are 2 tables I didn't include, customer_customer_demo and customer_demographics, because both tables are empty and contain no data, so in my opinion, there is no need to add them into the database.
SELECT e.first_name, e.last_name, COUNT(o.order_id) AS total_orders
FROM employees e
INNER JOIN orders o ON e.employee_id = o.employee_id
GROUP BY o.employee_id
ORDER BY total_orders DESC
LIMIT 5;`
SELECT first_name, last_name, total_orders,
CASE
WHEN total_orders >= 100 THEN 'Great'
WHEN total_orders < 100 AND total_orders >= 50 THEN 'Average'
WHEN total_orders < 50 THEN 'Poor'
END AS performance
FROM (
SELECT e.first_name, e.last_name, COUNT(o.order_id) AS total_orders
FROM employees e
INNER JOIN orders o ON e.employee_id = o.employee_id
GROUP BY o.employee_id) AS new_table
ORDER BY total_orders desc;
SELECT DISTINCT c.customer_id, c.customer_name, c.contact_name, c.address, c.city, c.country
FROM ((customers c
INNER JOIN orders o ON c.customer_id = o.customer_id)
INNER JOIN employees e ON o.employee_id = e.employee_id and e.last_name='Callahan' AND e.first_name='Laura')
ORDER BY c.customer_id;
SELECT DISTINCT p.product_id, p.product_name, p.quantity_per_unit, p.unit_price
FROM ((products p
INNER JOIN order_details od on p.product_id = od.product_id)
INNER JOIN orders o ON od.order_id = o.order_id AND o.order_date BETWEEN '1996-08-01' AND '1996-08-30')
ORDER BY p.unit_price DESC;
SELECT o.order_id, o.order_date, ROUND((od.unit_price * od.quantity), 2) as sales, ROUND(((od.unit_price * od.quantity) - (od.discount * od.unit_price * od.quantity)), 2) as net_sales
FROM ((order_details od
INNER JOIN products p ON od.product_id = p.product_id AND p.product_name = 'Ipoh Coffee')
INNER JOIN orders o ON od.order_id = o.order_id AND o.order_date BETWEEN '1996-09-01' AND '1996-12-31');
SELECT p.product_name, ROUND(SUM((od.unit_price * od.quantity) - (od.discount * od.unit_price * od.quantity)), 2) as total_sales
FROM ((order_details od
INNER JOIN products p ON od.product_id = p.product_id AND p.product_name = 'Ipoh Coffee')
INNER JOIN orders o ON od.order_id = o.order_id AND o.order_date BETWEEN '1996-09-01' AND '1996-12-31');