Level 1 project: a customer call list and a reorder list
To wrap up level 1 you build two lists that every business needs: a call list for the sales team and a reorder list for the warehouse. Each query combines several pieces you have already practiced one at a time.
You need: WHERE, AND and OR, IN and BETWEEN, IS NULL and IS NOT NULL, ORDER BY and LIMIT, and calculations with AS. You have practiced each of them on its own in level 1. This is the first time they come together.
The situation
The office supply shop from the exercises has two requests waiting. Sales wants to call long-standing customers today but only has time for five calls. And the warehouse needs a list of products to reorder, with what each order will cost.
Both lists come from a single table. The hard part is not a new command; it is putting the pieces in the right order and not forgetting a condition.
The project
Part 1: a call list for sales
You are looking for customers in two countries who have a phone number, oldest customers first, five at most. Read the task twice and jot down the conditions before you start typing.
Task Sales is calling long-standing customers today and has time for five calls. Find customers in the USA and the UK who have a phone number on file, oldest customers first (by customer_since), at most 5. Columns: customer (the name), city, phone and customer_since, in this order and with exactly these names.
customers 12 rows, 7 columns
| customer_id | name | city | country | customer_since | segment | phone |
|---|---|---|---|---|---|---|
| 1 | Harbor Fremont Partners | Boston | USA | 2021-03-15 | Business | 617-555-0142 |
| 2 | Emily Carter | Chicago | USA | 2022-07-01 | Consumer | NULL |
| 3 | Riverside County Office | Riverside | USA | 2020-11-20 | Government | 951-555-0110 |
| 4 | Raj Patel | Leeds | UK | 2023-01-09 | Consumer | 0113 496 0123 |
| 5 | Lakeview Hotel Ltd | Manchester | UK | 2022-04-18 | Business | 0161 496 0456 |
| 6 | Olivia Brooks | Austin | USA | 2024-02-27 | Consumer | NULL |
| 7 | Greene & Shaw LLP | London | UK | 2021-09-05 | Business | 020 7946 0321 |
| 8 | Maple Grove High School | Austin | USA | 2023-08-14 | School | 512-555-0187 |
| 9 | Chloe Evans | Boston | USA | 2025-05-30 | Consumer | 617-555-0199 |
| 10 | Northline Printing Co | Toronto | Canada | 2020-06-12 | Business | 416-555-0133 |
| 11 | Daniel Kim | Seattle | USA | 2024-10-03 | Consumer | NULL |
| 12 | Westbrook Dental Clinic | Chicago | USA | 2022-12-01 | Business | 312-555-0164 |
Part 2: a reorder list for the warehouse
Now there is math involved. The warehouse keeps at least 20 units of each product. Anything below that is topped up to 20, except furniture.
Task The warehouse keeps at least 20 units of every product in stock. Build the reorder list: all products with fewer than 20 units, except the Furniture category (the manufacturer ships those directly). Columns: product (the name), stock, reorder_qty (how many units are missing to reach 20) and reorder_cost (that quantity times the price). Sorted by reorder_cost, highest first.
products 12 rows, 5 columns
| product_id | name | category | price | stock |
|---|---|---|---|---|
| 1 | Copy paper, 500 sheets | Paper | 4.99 | 420 |
| 2 | Blue ballpoint pens, 10-pack | Writing | 3.49 | 310 |
| 3 | Lever arch file, gray | Filing | 2.79 | 185 |
| 4 | Comfort office chair | Furniture | 189 | 12 |
| 5 | Standing desk | Furniture | 449 | 5 |
| 6 | Black ink cartridge | Printer supplies | 24.9 | 64 |
| 7 | Yellow sticky notes, 12 pads | Writing | 6.99 | 0 |
| 8 | Mono laser printer L30 | Electronics | 219 | 8 |
| 9 | 27-inch monitor | Electronics | 279 | 15 |
| 10 | Notebook A5, ruled | Paper | 5.49 | 140 |
| 11 | Black toner XL | Printer supplies | 89.9 | 22 |
| 12 | Cross-cut shredder | Electronics | 129 | 0 |
What matters
The order of the clauses
A query always follows the same order: SELECT, FROM, WHERE, ORDER BY, LIMIT. Build it in that order too, and run it after every step. Start with SELECT and FROM, add the first condition, then the second, then the sort. After each step you can see whether the row count shrinks the way you expect.
Missing values need IS NULL
A missing phone number is NULL. phone <> NULL or phone != NULL is never true, not even for customers who do have a number. The condition you want is phone IS NOT NULL.
Sort first, then cut
LIMIT takes the first rows of the sorted result. Without ORDER BY you would get any five customers. With ORDER BY customer_since the longest-standing customers come first, because dates are stored as YYYY-MM-DD and therefore sort correctly as text.
Parentheses in the calculation
The reorder cost is the missing quantity times the price: (20 - stock) * price. Without parentheses SQL multiplies first and subtracts stock times price from 20. You can use the AS name in ORDER BY; in WHERE, write your conditions on the columns themselves.
If it doesn't work
- Press Run and compare your result with the table above the editor. If a customer is missing or one too many shows up, the problem is in WHERE.
- If a customer without a phone number is on the list,
IS NOT NULLis missing. If Northline Printing from Toronto is at the top, the country condition is missing. - When you mix AND and OR, add parentheses:
(country = 'USA' OR country = 'UK') AND phone IS NOT NULL. With IN you don't need them. - The countries are stored as USA and UK. 'US' finds nothing, and the check tells you that too few rows came back.
- If the check says "The values are right, but the columns have other names", an AS is missing. The message lists the names it wants.
- If the rows are right but in the wrong order, check ASC and DESC. The highest reorder cost belongs at the top.
- Both parts are also checked against different data. Typing customer IDs or product names into the condition will fail for that reason.
What you have learned in level 1
Besides the pieces in this project, level 1 also covered LIKE for text patterns, such as every customer whose name contains "Ltd", and DISTINCT for lists without repeats. With those you can pull almost any list an office needs out of a single table. What is still missing are totals and counts across many rows, and queries over several tables. That is what the next levels are about.
FAQ
How many points is the project worth?
Each of the two project tasks counts three times as much as a single exercise, because you have to solve several steps at once.
Is the project free?
Yes. All of level 1 is free, including this project.
Is there only one correct answer?
No. The check looks at your result, not the wording of your query. country IN ('USA', 'UK') and two OR conditions in parentheses are equally good. Only IS NOT NULL, ORDER BY and LIMIT must appear, because that is exactly what the task is about.
What if I get stuck?
The hints under each task help in three steps: first the idea, then the structure, then an almost finished query. If you are still stuck, go back to the lesson for the piece that trips you up. The links are at the top of this page.