Level 2 project: sales report
To finish level 2 you build two reports every management team asks for: revenue by month and category for the half-year review, and a split of customers into tiers A, B and C. Each query combines counting, totals, groups, conditions and dates.
You will need: COUNT, SUM and AVG, GROUP BY, HAVING, CASE WHEN, plus string and date functions. You practiced each one on its own in level 2. This is where they meet.
The situation
The office supplies shop from the exercises has a financial year behind it. The sales table holds every order line from June 2025 to June 2026: order number, date, customer, category, product, quantity, amount and status. An order with three products therefore takes up three rows. Some orders were cancelled; their lines have the status cancelled and must not show up in any revenue figure.
Everything sits in one table, much like a typical export from an inventory or ERP system. That means you do not need to combine several tables. The challenge is putting every condition in the right place.
The project
Part 1: revenue by month and category
The half-year review covers January to June 2026 only. You are looking for the month and category combinations that brought in at least 250. Before you type, note which condition is about single rows and which is about the total of a group.
Task For the half-year review, management wants to know which categories did well in which month. Analyze the first half of 2026 (January to June), without cancelled lines. Per month and category: sales_month (YYYY-MM), category, line_count (number of order lines) and revenue (the sum of amount, rounded to two decimals). Only show combinations with revenue of at least 250. Sorted by sales_month, and within a month highest revenue first.
sales 57 rows, 9 columns
| sale_id | order_id | order_date | customer | category | product | quantity | amount | status |
|---|---|---|---|---|---|---|---|---|
| 1 | 2001 | 2025-06-07 | Harbor Fremont Partners | Paper | Copy paper, 500 sheets | 32 | 153.28 | cancelled |
| 2 | 2001 | 2025-06-07 | Harbor Fremont Partners | Electronics | Cross-cut shredder | 1 | 129 | cancelled |
| 3 | 2001 | 2025-06-07 | Harbor Fremont Partners | Printer supplies | Black ink cartridge | 3 | 74.7 | cancelled |
| 4 | 2002 | 2025-06-12 | Northline Printing Co | Paper | Notebook A5, ruled | 17 | 93.33 | delivered |
| 5 | 2002 | 2025-06-12 | Northline Printing Co | Writing | Blue ballpoint pens, 10-pack | 14 | 48.86 | delivered |
| 6 | 2002 | 2025-06-12 | Northline Printing Co | Printer supplies | Black toner XL | 3 | 269.7 | delivered |
| 7 | 2003 | 2025-06-27 | Maple Grove High School | Writing | Blue ballpoint pens, 10-pack | 21 | 73.29 | delivered |
| 8 | 2003 | 2025-06-27 | Maple Grove High School | Electronics | 27-inch monitor | 3 | 837 | delivered |
| 9 | 2004 | 2025-07-08 | Westbrook Dental Clinic | Writing | Yellow sticky notes, 12 pads | 2 | 13.98 | delivered |
| 10 | 2004 | 2025-07-08 | Westbrook Dental Clinic | Paper | Notebook A5, ruled | 10 | 54.9 | delivered |
| 11 | 2005 | 2025-07-17 | Chloe Evans | Filing | Lever arch file, gray | 13 | 36.27 | delivered |
| 12 | 2005 | 2025-07-17 | Chloe Evans | Writing | Blue ballpoint pens, 10-pack | 5 | 17.45 | delivered |
| 13 | 2006 | 2025-07-26 | Westbrook Dental Clinic | Furniture | Comfort office chair | 2 | 358 | delivered |
| 14 | 2007 | 2025-08-04 | Riverside County Office | Printer supplies | Black ink cartridge | 4 | 99.6 | delivered |
| 15 | 2007 | 2025-08-04 | Riverside County Office | Electronics | Mono laser printer L30 | 1 | 219 | delivered |
| 16 | 2008 | 2025-08-06 | Raj Patel | Paper | Copy paper, 500 sheets | 12 | 57.48 | delivered |
| 17 | 2008 | 2025-08-06 | Raj Patel | Furniture | Comfort office chair | 2 | 358 | delivered |
| 18 | 2009 | 2025-08-26 | Chloe Evans | Electronics | 27-inch monitor | 1 | 279 | delivered |
| 19 | 2010 | 2025-09-05 | Westbrook Dental Clinic | Furniture | Comfort office chair | 1 | 179 | delivered |
| 20 | 2010 | 2025-09-05 | Westbrook Dental Clinic | Printer supplies | Black ink cartridge | 2 | 49.8 | delivered |
| 21 | 2011 | 2025-09-10 | Olivia Brooks | Electronics | 27-inch monitor | 1 | 279 | delivered |
| 22 | 2012 | 2025-09-13 | Northline Printing Co | Writing | Blue ballpoint pens, 10-pack | 21 | 73.29 | delivered |
| 23 | 2013 | 2025-10-09 | Maple Grove High School | Electronics | 27-inch monitor | 3 | 837 | cancelled |
| 24 | 2013 | 2025-10-09 | Maple Grove High School | Filing | Lever arch file, gray | 10 | 27.9 | cancelled |
| 25 | 2014 | 2025-10-24 | Raj Patel | Writing | Yellow sticky notes, 12 pads | 3 | 20.97 | delivered |
| 26 | 2015 | 2025-10-25 | Greene & Shaw LLP | Writing | Yellow sticky notes, 12 pads | 8 | 55.92 | cancelled |
| 27 | 2015 | 2025-10-25 | Greene & Shaw LLP | Electronics | 27-inch monitor | 2 | 558 | cancelled |
| 28 | 2015 | 2025-10-25 | Greene & Shaw LLP | Paper | Notebook A5, ruled | 20 | 109.8 | cancelled |
| 29 | 2016 | 2025-11-19 | Northline Printing Co | Writing | Blue ballpoint pens, 10-pack | 16 | 55.84 | cancelled |
| 30 | 2017 | 2025-11-22 | Emily Carter | Filing | Lever arch file, gray | 14 | 39.06 | delivered |
| 31 | 2018 | 2025-11-24 | Chloe Evans | Furniture | Comfort office chair | 2 | 358 | delivered |
| 32 | 2018 | 2025-11-24 | Chloe Evans | Writing | Yellow sticky notes, 12 pads | 2 | 13.98 | delivered |
| 33 | 2019 | 2025-12-09 | Northline Printing Co | Furniture | Standing desk | 2 | 898 | delivered |
| 34 | 2019 | 2025-12-09 | Northline Printing Co | Paper | Notebook A5, ruled | 34 | 186.66 | delivered |
| 35 | 2020 | 2025-12-26 | Lakeview Hotel Ltd | Writing | Blue ballpoint pens, 10-pack | 40 | 139.6 | delivered |
| 36 | 2020 | 2025-12-26 | Lakeview Hotel Ltd | Furniture | Comfort office chair | 3 | 537 | delivered |
| 37 | 2021 | 2026-01-03 | Westbrook Dental Clinic | Paper | Copy paper, 500 sheets | 24 | 114.96 | delivered |
| 38 | 2021 | 2026-01-03 | Westbrook Dental Clinic | Electronics | 27-inch monitor | 1 | 279 | delivered |
| 39 | 2022 | 2026-01-06 | Northline Printing Co | Printer supplies | Black ink cartridge | 3 | 74.7 | delivered |
| 40 | 2023 | 2026-02-03 | Lakeview Hotel Ltd | Writing | Yellow sticky notes, 12 pads | 2 | 13.98 | delivered |
| 41 | 2024 | 2026-02-23 | Chloe Evans | Writing | Blue ballpoint pens, 10-pack | 5 | 17.45 | delivered |
| 42 | 2025 | 2026-03-09 | Raj Patel | Furniture | Comfort office chair | 2 | 358 | delivered |
| 43 | 2026 | 2026-03-20 | Harbor Fremont Partners | Writing | Blue ballpoint pens, 10-pack | 27 | 94.23 | delivered |
| 44 | 2026 | 2026-03-20 | Harbor Fremont Partners | Furniture | Standing desk | 2 | 898 | delivered |
| 45 | 2026 | 2026-03-20 | Harbor Fremont Partners | Printer supplies | Black ink cartridge | 10 | 249 | delivered |
| 46 | 2027 | 2026-04-07 | Northline Printing Co | Electronics | Cross-cut shredder | 1 | 129 | delivered |
| 47 | 2027 | 2026-04-07 | Northline Printing Co | Furniture | Comfort office chair | 2 | 358 | delivered |
| 48 | 2028 | 2026-04-08 | Greene & Shaw LLP | Paper | Notebook A5, ruled | 50 | 274.5 | cancelled |
| 49 | 2028 | 2026-04-08 | Greene & Shaw LLP | Filing | Lever arch file, gray | 12 | 33.48 | cancelled |
| 50 | 2029 | 2026-05-09 | Greene & Shaw LLP | Filing | Lever arch file, gray | 41 | 114.39 | delivered |
| 51 | 2029 | 2026-05-09 | Greene & Shaw LLP | Paper | Notebook A5, ruled | 57 | 312.93 | delivered |
| 52 | 2030 | 2026-05-13 | Maple Grove High School | Paper | Notebook A5, ruled | 21 | 115.29 | delivered |
| 53 | 2031 | 2026-06-14 | Olivia Brooks | Paper | Notebook A5, ruled | 18 | 98.82 | shipped |
| 54 | 2031 | 2026-06-14 | Olivia Brooks | Electronics | 27-inch monitor | 1 | 279 | shipped |
| 55 | 2032 | 2026-06-19 | Northline Printing Co | Filing | Lever arch file, gray | 14 | 39.06 | open |
| 56 | 2032 | 2026-06-19 | Northline Printing Co | Paper | Notebook A5, ruled | 46 | 252.54 | open |
| 57 | 2032 | 2026-06-19 | Northline Printing Co | Writing | Blue ballpoint pens, 10-pack | 21 | 73.29 | open |
This exercise is part of Premium.
Premium unlocks every exercise in every lesson, unlimited practice with fresh tasks and the final test with certificate.
See Premium Already Premium? Log in
Part 2: sort customers into tiers A, B and C
Sales wants to know which customers deserve attention first. The tier follows revenue in the financial year from July 2025 to June 2026. The report also shows the number of orders, and there is a trap: one order can have several rows.
Task Sales sorts customers into tiers by their revenue in the financial year that runs from 1 July 2025 to 30 June 2026. Cancelled lines do not count. Per customer: customer, order_count (number of different orders), revenue (the sum of amount, rounded to two decimals) and tier: A from 1000 revenue, B from 500, otherwise C. Sorted by revenue, highest first.
sales 57 rows, 9 columns
| sale_id | order_id | order_date | customer | category | product | quantity | amount | status |
|---|---|---|---|---|---|---|---|---|
| 1 | 2001 | 2025-06-07 | Harbor Fremont Partners | Paper | Copy paper, 500 sheets | 32 | 153.28 | cancelled |
| 2 | 2001 | 2025-06-07 | Harbor Fremont Partners | Electronics | Cross-cut shredder | 1 | 129 | cancelled |
| 3 | 2001 | 2025-06-07 | Harbor Fremont Partners | Printer supplies | Black ink cartridge | 3 | 74.7 | cancelled |
| 4 | 2002 | 2025-06-12 | Northline Printing Co | Paper | Notebook A5, ruled | 17 | 93.33 | delivered |
| 5 | 2002 | 2025-06-12 | Northline Printing Co | Writing | Blue ballpoint pens, 10-pack | 14 | 48.86 | delivered |
| 6 | 2002 | 2025-06-12 | Northline Printing Co | Printer supplies | Black toner XL | 3 | 269.7 | delivered |
| 7 | 2003 | 2025-06-27 | Maple Grove High School | Writing | Blue ballpoint pens, 10-pack | 21 | 73.29 | delivered |
| 8 | 2003 | 2025-06-27 | Maple Grove High School | Electronics | 27-inch monitor | 3 | 837 | delivered |
| 9 | 2004 | 2025-07-08 | Westbrook Dental Clinic | Writing | Yellow sticky notes, 12 pads | 2 | 13.98 | delivered |
| 10 | 2004 | 2025-07-08 | Westbrook Dental Clinic | Paper | Notebook A5, ruled | 10 | 54.9 | delivered |
| 11 | 2005 | 2025-07-17 | Chloe Evans | Filing | Lever arch file, gray | 13 | 36.27 | delivered |
| 12 | 2005 | 2025-07-17 | Chloe Evans | Writing | Blue ballpoint pens, 10-pack | 5 | 17.45 | delivered |
| 13 | 2006 | 2025-07-26 | Westbrook Dental Clinic | Furniture | Comfort office chair | 2 | 358 | delivered |
| 14 | 2007 | 2025-08-04 | Riverside County Office | Printer supplies | Black ink cartridge | 4 | 99.6 | delivered |
| 15 | 2007 | 2025-08-04 | Riverside County Office | Electronics | Mono laser printer L30 | 1 | 219 | delivered |
| 16 | 2008 | 2025-08-06 | Raj Patel | Paper | Copy paper, 500 sheets | 12 | 57.48 | delivered |
| 17 | 2008 | 2025-08-06 | Raj Patel | Furniture | Comfort office chair | 2 | 358 | delivered |
| 18 | 2009 | 2025-08-26 | Chloe Evans | Electronics | 27-inch monitor | 1 | 279 | delivered |
| 19 | 2010 | 2025-09-05 | Westbrook Dental Clinic | Furniture | Comfort office chair | 1 | 179 | delivered |
| 20 | 2010 | 2025-09-05 | Westbrook Dental Clinic | Printer supplies | Black ink cartridge | 2 | 49.8 | delivered |
| 21 | 2011 | 2025-09-10 | Olivia Brooks | Electronics | 27-inch monitor | 1 | 279 | delivered |
| 22 | 2012 | 2025-09-13 | Northline Printing Co | Writing | Blue ballpoint pens, 10-pack | 21 | 73.29 | delivered |
| 23 | 2013 | 2025-10-09 | Maple Grove High School | Electronics | 27-inch monitor | 3 | 837 | cancelled |
| 24 | 2013 | 2025-10-09 | Maple Grove High School | Filing | Lever arch file, gray | 10 | 27.9 | cancelled |
| 25 | 2014 | 2025-10-24 | Raj Patel | Writing | Yellow sticky notes, 12 pads | 3 | 20.97 | delivered |
| 26 | 2015 | 2025-10-25 | Greene & Shaw LLP | Writing | Yellow sticky notes, 12 pads | 8 | 55.92 | cancelled |
| 27 | 2015 | 2025-10-25 | Greene & Shaw LLP | Electronics | 27-inch monitor | 2 | 558 | cancelled |
| 28 | 2015 | 2025-10-25 | Greene & Shaw LLP | Paper | Notebook A5, ruled | 20 | 109.8 | cancelled |
| 29 | 2016 | 2025-11-19 | Northline Printing Co | Writing | Blue ballpoint pens, 10-pack | 16 | 55.84 | cancelled |
| 30 | 2017 | 2025-11-22 | Emily Carter | Filing | Lever arch file, gray | 14 | 39.06 | delivered |
| 31 | 2018 | 2025-11-24 | Chloe Evans | Furniture | Comfort office chair | 2 | 358 | delivered |
| 32 | 2018 | 2025-11-24 | Chloe Evans | Writing | Yellow sticky notes, 12 pads | 2 | 13.98 | delivered |
| 33 | 2019 | 2025-12-09 | Northline Printing Co | Furniture | Standing desk | 2 | 898 | delivered |
| 34 | 2019 | 2025-12-09 | Northline Printing Co | Paper | Notebook A5, ruled | 34 | 186.66 | delivered |
| 35 | 2020 | 2025-12-26 | Lakeview Hotel Ltd | Writing | Blue ballpoint pens, 10-pack | 40 | 139.6 | delivered |
| 36 | 2020 | 2025-12-26 | Lakeview Hotel Ltd | Furniture | Comfort office chair | 3 | 537 | delivered |
| 37 | 2021 | 2026-01-03 | Westbrook Dental Clinic | Paper | Copy paper, 500 sheets | 24 | 114.96 | delivered |
| 38 | 2021 | 2026-01-03 | Westbrook Dental Clinic | Electronics | 27-inch monitor | 1 | 279 | delivered |
| 39 | 2022 | 2026-01-06 | Northline Printing Co | Printer supplies | Black ink cartridge | 3 | 74.7 | delivered |
| 40 | 2023 | 2026-02-03 | Lakeview Hotel Ltd | Writing | Yellow sticky notes, 12 pads | 2 | 13.98 | delivered |
| 41 | 2024 | 2026-02-23 | Chloe Evans | Writing | Blue ballpoint pens, 10-pack | 5 | 17.45 | delivered |
| 42 | 2025 | 2026-03-09 | Raj Patel | Furniture | Comfort office chair | 2 | 358 | delivered |
| 43 | 2026 | 2026-03-20 | Harbor Fremont Partners | Writing | Blue ballpoint pens, 10-pack | 27 | 94.23 | delivered |
| 44 | 2026 | 2026-03-20 | Harbor Fremont Partners | Furniture | Standing desk | 2 | 898 | delivered |
| 45 | 2026 | 2026-03-20 | Harbor Fremont Partners | Printer supplies | Black ink cartridge | 10 | 249 | delivered |
| 46 | 2027 | 2026-04-07 | Northline Printing Co | Electronics | Cross-cut shredder | 1 | 129 | delivered |
| 47 | 2027 | 2026-04-07 | Northline Printing Co | Furniture | Comfort office chair | 2 | 358 | delivered |
| 48 | 2028 | 2026-04-08 | Greene & Shaw LLP | Paper | Notebook A5, ruled | 50 | 274.5 | cancelled |
| 49 | 2028 | 2026-04-08 | Greene & Shaw LLP | Filing | Lever arch file, gray | 12 | 33.48 | cancelled |
| 50 | 2029 | 2026-05-09 | Greene & Shaw LLP | Filing | Lever arch file, gray | 41 | 114.39 | delivered |
| 51 | 2029 | 2026-05-09 | Greene & Shaw LLP | Paper | Notebook A5, ruled | 57 | 312.93 | delivered |
| 52 | 2030 | 2026-05-13 | Maple Grove High School | Paper | Notebook A5, ruled | 21 | 115.29 | delivered |
| 53 | 2031 | 2026-06-14 | Olivia Brooks | Paper | Notebook A5, ruled | 18 | 98.82 | shipped |
| 54 | 2031 | 2026-06-14 | Olivia Brooks | Electronics | 27-inch monitor | 1 | 279 | shipped |
| 55 | 2032 | 2026-06-19 | Northline Printing Co | Filing | Lever arch file, gray | 14 | 39.06 | open |
| 56 | 2032 | 2026-06-19 | Northline Printing Co | Paper | Notebook A5, ruled | 46 | 252.54 | open |
| 57 | 2032 | 2026-06-19 | Northline Printing Co | Writing | Blue ballpoint pens, 10-pack | 21 | 73.29 | open |
This exercise is part of Premium.
Premium unlocks every exercise in every lesson, unlimited practice with fresh tasks and the final test with certificate.
See Premium Already Premium? Log in
What matters
WHERE or HAVING
WHERE tests each row before anything is grouped, so the period and the status belong there. HAVING tests a group once it exists, for example SUM(amount) >= 250. Write amount >= 250 in WHERE and every small line is gone before the adding starts, so the totals come out wrong. Write SUM(amount) in WHERE and the exercise reminds you that aggregate functions do not work in WHERE and that conditions on groups go in HAVING.
Month, not date
Grouping by order_date gives one group per day. For months you need strftime('%Y-%m', order_date) or substr(order_date, 1, 7). Both return 2026-03 and sort correctly. You may reuse the AS name in GROUP BY and ORDER BY.
Counting rows or orders
COUNT(*) counts rows, which here means order lines. For the number of orders, count each order number once: COUNT(DISTINCT order_id). With COUNT(*), Northline Printing would get 9 orders instead of 5.
CASE on the total
Inside CASE you cannot use the name revenue from the same SELECT list; the exercise then says that the column revenue does not exist. Write out the sum: CASE WHEN SUM(amount) >= 1000 THEN 'A' …. The highest threshold goes first, because CASE takes the first condition that is true.
If you get stuck
- Build the query in steps and press Run along the way: WHERE first, then GROUP BY with SUM, then HAVING, and ORDER BY last.
- If months from 2025 appear, the date range is missing. Write dates as YYYY-MM-DD in single quotes.
- If the cancelled paper order from April shows up, the status filter is missing.
- If the rows are right but in the wrong order, check ORDER BY: in part 1 by month first, then by revenue, highest first.
- If the checker says the values are right but the columns have different names, an AS is missing. The message lists the names it expects.
- Both parts are also checked against different data. Typing customers or months straight into the query will not pass.
What you learned in level 2
COUNT, SUM, AVG, MIN and MAX turn many rows into one number, GROUP BY does that for each group separately, and HAVING filters the groups. CASE sorts values into classes, and string and date functions prepare columns for a report. That covers most questions an office will ever ask of a single table. What is still missing is combining data from several tables, such as orders with customer details. That is what level 3 is about.
FAQ
How many points is the project worth?
Each of the two project tasks counts three times as much as a regular exercise, because you have to solve several steps at once.
Is the project free?
No. Projects from level 2 onwards are part of Premium. The first exercise of every lesson is free, the projects are not.
Is there only one correct answer?
No. The checker compares your result, not the text of your query. strftime('%Y-%m', order_date) and substr(order_date, 1, 7) are equally good, and so are BETWEEN and two comparisons joined with AND. Only GROUP BY and HAVING in part 1, and GROUP BY and CASE in part 2, must appear, because that is what the task is about.
Why a new table instead of the shop tables?
In the shop, date and status live in orders, category and price in products, and quantities in order_items. Revenue by category would mean combining all three, which comes in level 3. The sales table has everything in one row, like an export made for reporting.