Back to Practice
#0361
Lowest Revenue Product Per Category
MediumSQL24 min20 XP
Problem
Return category, product, and revenue for the lowest revenue product in each category.
Why This Matters
SQL interviews usually test whether you can turn a business question into the right rows, grouping level, join type, and edge-case behavior.
Schema
sales(category TEXT, product TEXT, revenue INTEGER)
Examples
Example 1
Inputp2 and q2 are lowest in their categories
Outputp2 and q2
Sorting revenue ascending makes the lowest row rank 1.
Constraints
- Return only the requested columns.
- Use deterministic ORDER BY when multiple rows are returned.
- Assume SQLite-compatible SQL unless the prompt states otherwise.
CodeSQL
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core SQL case
Inputp2 and q2 are lowest in their categories
Expected[["A","p2",80],["B","q2",40]]
Sorting revenue ascending makes the lowest row rank 1.
Hidden Test Categories
Empty or missing matchesDuplicate rows or tiesNULL values where the pattern commonly breaks