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_idorder_idorder_datecustomercategoryproductquantityamountstatus
120012025-06-07Harbor Fremont PartnersPaperCopy paper, 500 sheets32153.28cancelled
220012025-06-07Harbor Fremont PartnersElectronicsCross-cut shredder1129cancelled
320012025-06-07Harbor Fremont PartnersPrinter suppliesBlack ink cartridge374.7cancelled
420022025-06-12Northline Printing CoPaperNotebook A5, ruled1793.33delivered
520022025-06-12Northline Printing CoWritingBlue ballpoint pens, 10-pack1448.86delivered
620022025-06-12Northline Printing CoPrinter suppliesBlack toner XL3269.7delivered
720032025-06-27Maple Grove High SchoolWritingBlue ballpoint pens, 10-pack2173.29delivered
820032025-06-27Maple Grove High SchoolElectronics27-inch monitor3837delivered
920042025-07-08Westbrook Dental ClinicWritingYellow sticky notes, 12 pads213.98delivered
1020042025-07-08Westbrook Dental ClinicPaperNotebook A5, ruled1054.9delivered
1120052025-07-17Chloe EvansFilingLever arch file, gray1336.27delivered
1220052025-07-17Chloe EvansWritingBlue ballpoint pens, 10-pack517.45delivered
1320062025-07-26Westbrook Dental ClinicFurnitureComfort office chair2358delivered
1420072025-08-04Riverside County OfficePrinter suppliesBlack ink cartridge499.6delivered
1520072025-08-04Riverside County OfficeElectronicsMono laser printer L301219delivered
1620082025-08-06Raj PatelPaperCopy paper, 500 sheets1257.48delivered
1720082025-08-06Raj PatelFurnitureComfort office chair2358delivered
1820092025-08-26Chloe EvansElectronics27-inch monitor1279delivered
1920102025-09-05Westbrook Dental ClinicFurnitureComfort office chair1179delivered
2020102025-09-05Westbrook Dental ClinicPrinter suppliesBlack ink cartridge249.8delivered
2120112025-09-10Olivia BrooksElectronics27-inch monitor1279delivered
2220122025-09-13Northline Printing CoWritingBlue ballpoint pens, 10-pack2173.29delivered
2320132025-10-09Maple Grove High SchoolElectronics27-inch monitor3837cancelled
2420132025-10-09Maple Grove High SchoolFilingLever arch file, gray1027.9cancelled
2520142025-10-24Raj PatelWritingYellow sticky notes, 12 pads320.97delivered
2620152025-10-25Greene & Shaw LLPWritingYellow sticky notes, 12 pads855.92cancelled
2720152025-10-25Greene & Shaw LLPElectronics27-inch monitor2558cancelled
2820152025-10-25Greene & Shaw LLPPaperNotebook A5, ruled20109.8cancelled
2920162025-11-19Northline Printing CoWritingBlue ballpoint pens, 10-pack1655.84cancelled
3020172025-11-22Emily CarterFilingLever arch file, gray1439.06delivered
3120182025-11-24Chloe EvansFurnitureComfort office chair2358delivered
3220182025-11-24Chloe EvansWritingYellow sticky notes, 12 pads213.98delivered
3320192025-12-09Northline Printing CoFurnitureStanding desk2898delivered
3420192025-12-09Northline Printing CoPaperNotebook A5, ruled34186.66delivered
3520202025-12-26Lakeview Hotel LtdWritingBlue ballpoint pens, 10-pack40139.6delivered
3620202025-12-26Lakeview Hotel LtdFurnitureComfort office chair3537delivered
3720212026-01-03Westbrook Dental ClinicPaperCopy paper, 500 sheets24114.96delivered
3820212026-01-03Westbrook Dental ClinicElectronics27-inch monitor1279delivered
3920222026-01-06Northline Printing CoPrinter suppliesBlack ink cartridge374.7delivered
4020232026-02-03Lakeview Hotel LtdWritingYellow sticky notes, 12 pads213.98delivered
4120242026-02-23Chloe EvansWritingBlue ballpoint pens, 10-pack517.45delivered
4220252026-03-09Raj PatelFurnitureComfort office chair2358delivered
4320262026-03-20Harbor Fremont PartnersWritingBlue ballpoint pens, 10-pack2794.23delivered
4420262026-03-20Harbor Fremont PartnersFurnitureStanding desk2898delivered
4520262026-03-20Harbor Fremont PartnersPrinter suppliesBlack ink cartridge10249delivered
4620272026-04-07Northline Printing CoElectronicsCross-cut shredder1129delivered
4720272026-04-07Northline Printing CoFurnitureComfort office chair2358delivered
4820282026-04-08Greene & Shaw LLPPaperNotebook A5, ruled50274.5cancelled
4920282026-04-08Greene & Shaw LLPFilingLever arch file, gray1233.48cancelled
5020292026-05-09Greene & Shaw LLPFilingLever arch file, gray41114.39delivered
5120292026-05-09Greene & Shaw LLPPaperNotebook A5, ruled57312.93delivered
5220302026-05-13Maple Grove High SchoolPaperNotebook A5, ruled21115.29delivered
5320312026-06-14Olivia BrooksPaperNotebook A5, ruled1898.82shipped
5420312026-06-14Olivia BrooksElectronics27-inch monitor1279shipped
5520322026-06-19Northline Printing CoFilingLever arch file, gray1439.06open
5620322026-06-19Northline Printing CoPaperNotebook A5, ruled46252.54open
5720322026-06-19Northline Printing CoWritingBlue ballpoint pens, 10-pack2173.29open

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_idorder_idorder_datecustomercategoryproductquantityamountstatus
120012025-06-07Harbor Fremont PartnersPaperCopy paper, 500 sheets32153.28cancelled
220012025-06-07Harbor Fremont PartnersElectronicsCross-cut shredder1129cancelled
320012025-06-07Harbor Fremont PartnersPrinter suppliesBlack ink cartridge374.7cancelled
420022025-06-12Northline Printing CoPaperNotebook A5, ruled1793.33delivered
520022025-06-12Northline Printing CoWritingBlue ballpoint pens, 10-pack1448.86delivered
620022025-06-12Northline Printing CoPrinter suppliesBlack toner XL3269.7delivered
720032025-06-27Maple Grove High SchoolWritingBlue ballpoint pens, 10-pack2173.29delivered
820032025-06-27Maple Grove High SchoolElectronics27-inch monitor3837delivered
920042025-07-08Westbrook Dental ClinicWritingYellow sticky notes, 12 pads213.98delivered
1020042025-07-08Westbrook Dental ClinicPaperNotebook A5, ruled1054.9delivered
1120052025-07-17Chloe EvansFilingLever arch file, gray1336.27delivered
1220052025-07-17Chloe EvansWritingBlue ballpoint pens, 10-pack517.45delivered
1320062025-07-26Westbrook Dental ClinicFurnitureComfort office chair2358delivered
1420072025-08-04Riverside County OfficePrinter suppliesBlack ink cartridge499.6delivered
1520072025-08-04Riverside County OfficeElectronicsMono laser printer L301219delivered
1620082025-08-06Raj PatelPaperCopy paper, 500 sheets1257.48delivered
1720082025-08-06Raj PatelFurnitureComfort office chair2358delivered
1820092025-08-26Chloe EvansElectronics27-inch monitor1279delivered
1920102025-09-05Westbrook Dental ClinicFurnitureComfort office chair1179delivered
2020102025-09-05Westbrook Dental ClinicPrinter suppliesBlack ink cartridge249.8delivered
2120112025-09-10Olivia BrooksElectronics27-inch monitor1279delivered
2220122025-09-13Northline Printing CoWritingBlue ballpoint pens, 10-pack2173.29delivered
2320132025-10-09Maple Grove High SchoolElectronics27-inch monitor3837cancelled
2420132025-10-09Maple Grove High SchoolFilingLever arch file, gray1027.9cancelled
2520142025-10-24Raj PatelWritingYellow sticky notes, 12 pads320.97delivered
2620152025-10-25Greene & Shaw LLPWritingYellow sticky notes, 12 pads855.92cancelled
2720152025-10-25Greene & Shaw LLPElectronics27-inch monitor2558cancelled
2820152025-10-25Greene & Shaw LLPPaperNotebook A5, ruled20109.8cancelled
2920162025-11-19Northline Printing CoWritingBlue ballpoint pens, 10-pack1655.84cancelled
3020172025-11-22Emily CarterFilingLever arch file, gray1439.06delivered
3120182025-11-24Chloe EvansFurnitureComfort office chair2358delivered
3220182025-11-24Chloe EvansWritingYellow sticky notes, 12 pads213.98delivered
3320192025-12-09Northline Printing CoFurnitureStanding desk2898delivered
3420192025-12-09Northline Printing CoPaperNotebook A5, ruled34186.66delivered
3520202025-12-26Lakeview Hotel LtdWritingBlue ballpoint pens, 10-pack40139.6delivered
3620202025-12-26Lakeview Hotel LtdFurnitureComfort office chair3537delivered
3720212026-01-03Westbrook Dental ClinicPaperCopy paper, 500 sheets24114.96delivered
3820212026-01-03Westbrook Dental ClinicElectronics27-inch monitor1279delivered
3920222026-01-06Northline Printing CoPrinter suppliesBlack ink cartridge374.7delivered
4020232026-02-03Lakeview Hotel LtdWritingYellow sticky notes, 12 pads213.98delivered
4120242026-02-23Chloe EvansWritingBlue ballpoint pens, 10-pack517.45delivered
4220252026-03-09Raj PatelFurnitureComfort office chair2358delivered
4320262026-03-20Harbor Fremont PartnersWritingBlue ballpoint pens, 10-pack2794.23delivered
4420262026-03-20Harbor Fremont PartnersFurnitureStanding desk2898delivered
4520262026-03-20Harbor Fremont PartnersPrinter suppliesBlack ink cartridge10249delivered
4620272026-04-07Northline Printing CoElectronicsCross-cut shredder1129delivered
4720272026-04-07Northline Printing CoFurnitureComfort office chair2358delivered
4820282026-04-08Greene & Shaw LLPPaperNotebook A5, ruled50274.5cancelled
4920282026-04-08Greene & Shaw LLPFilingLever arch file, gray1233.48cancelled
5020292026-05-09Greene & Shaw LLPFilingLever arch file, gray41114.39delivered
5120292026-05-09Greene & Shaw LLPPaperNotebook A5, ruled57312.93delivered
5220302026-05-13Maple Grove High SchoolPaperNotebook A5, ruled21115.29delivered
5320312026-06-14Olivia BrooksPaperNotebook A5, ruled1898.82shipped
5420312026-06-14Olivia BrooksElectronics27-inch monitor1279shipped
5520322026-06-19Northline Printing CoFilingLever arch file, gray1439.06open
5620322026-06-19Northline Printing CoPaperNotebook A5, ruled46252.54open
5720322026-06-19Northline Printing CoWritingBlue ballpoint pens, 10-pack2173.29open

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.

Level 2 complete

Next comes level 3, combining tables: with JOIN you bring the customer name to every order and the product to every order line, instead of needing everything in one table.

Learn JOIN

Write to us

Choose language

Select your preferred language