About this problem
The business question
Finance noticed that the revenue on a customer dashboard was higher than what was actually invoiced. The dashboard joins orders to their line items and then sums the order totals. They need a corrected report.
Expected result: One row per customer with order_count, revenue (each order total counted once), and total units across their order items.
What you will practice
Tables
CREATE TABLE customers (
customer_id INT PRIMARY KEY,
customer_name VARCHAR(80) NOT NULL
);
CREATE TABLE orders (
order_id INT PRIMARY KEY,
customer_id INT NOT NULL REFERENCES customers(customer_id),
order_date DATE NOT NULL,
order_total NUMERIC(10, 2) NOT NULL
);
CREATE TABLE order_items (
item_id INT PRIMARY KEY,
order_id INT NOT NULL REFERENCES orders(order_id),
sku VARCHAR(20) NOT NULL,
quantity INT NOT NULL
);More Joins practice
20 problems in this topic, with key concepts and common mistakes.