IntermediateJoins25 points

Revenue by product category

The finance team reports revenue by category every month. Only orders that were not cancelled count as revenue. The revenue of a line is quantity × price.

Task: return each product category with its total revenue (rounded to 2 decimals), highest revenue first.

The data you can query

Each table is shown with its column types and the first rows, so you can see exactly what the data looks like.

customers14 rows
id INTEGERname TEXTcity TEXTsignup_date TEXT
1Ayesha KhanLahore2025-11-03
2Bilal AhmedKarachi2025-11-12
3Hina MalikIslamabad2025-12-01
4Usman TariqRawalpindi2025-12-15
5Sana IqbalLahore2026-01-04
6Omar FarooqFaisalabad2026-01-20

Showing the first 6 of 14 rows.

order_items80 rows
id INTEGERorder_id INTEGERproduct_id INTEGERquantity INTEGER
1112
2124
3261
4224
52104
6391

Showing the first 6 of 80 rows.

orders40 rows
id INTEGERcustomer_id INTEGERorder_date TEXTstatus TEXT
132026-01-16Delivered
2112026-06-14Delivered
372026-02-15Delivered
4102026-06-19Delivered
552026-01-06Delivered
692026-03-06Delivered

Showing the first 6 of 40 rows.

products10 rows
id INTEGERname TEXTcategory TEXTprice REAL
1Wireless MouseElectronics1850
2USB CableElectronics450
3Bluetooth SpeakerElectronics4200
4Notebook A4Stationery220
5Gel Pen PackStationery180
6Desk OrganizerStationery950

Showing the first 6 of 10 rows.

Your query runs on SQLite. Write a single SELECT; use LIMIT instead of TOP.

Need a hint?

Join order_items to products (for the price) and to orders (for the status), then GROUP BY category.