All courses
Intermediate

Join tables like an analyst

Combine customers, orders, products and people into one answer, find what is missing with LEFT JOIN, and keep your totals honest when tables multiply rows.

8 exercises · 36 minutes · Data: Online shop, Company team
Start course
SQL
01
→ 02
→ 03

Your exercises

01
Who ordered in September?

The orders table only stores customer_id, but the account manager wants names. For every order placed in September 2026 (any status), return order id, order_date and the customer's name. Sort by order_date, then by order id.

3 min
02
Top 5 customers by revenue

Sales wants to invite its five most valuable customers to a launch event. Return customer name and paid revenue (quantity × unit_price, paid orders only) rounded to 2 decimals for the top 5 customers, sorted by revenue from high to low. Treat each customer id as one customer.

4 min
03
What did discounts cost us?

Some order lines were sold below the catalogue price. For paid orders only, compare each line's unit_price with the product's list price (products.price). For every product that was sold at a discount, return product name and the total discount given in euros ((price − unit_price) × quantity, summed), rounded to 2 decimals. Sort by total discount from high to low.

5 min
04
Signed up, never ordered

Marketing wants to send a welcome discount to people who created an account but never placed a single order (of any status). Return name and signup_date of those customers.

4 min
05
Headcount per department

HR is preparing the hiring plan and needs the headcount of every department, including departments that have nobody yet. Return department name and number of employees, sorted by number of employees from high to low, then by department name A to Z.

4 min
06
Org chart with manager names

The employees table stores each person's manager as manager_id, which points to another row in the same table. For an org chart export, return every employee's name, their title, and their manager's name. The CEO has no manager: keep her in the list with NULL as manager name.

5 min
07
Channel scorecard without double counting

The board wants a scorecard per sales channel. Using paid orders only, return channel, number of paid orders, and paid revenue (quantity × unit_price) rounded to 2 decimals. Sort by revenue from high to low.

5 min
08
Paid above the department average

For the salary review, HR wants everyone who earns strictly more than the average salary of their own department. Return employee name, department name, salary, and the department's average salary rounded to 0 decimals. Sort by department name A to Z, then by salary from high to low.

6 min
Queries run on sample company data in SQLite. Core SELECT, JOIN and GROUP BY patterns transfer to other SQL engines; functions, dates and types can differ.