Back to Practice
#0349
Products Equal to Category Max
MediumSQL24 min20 XP
Problem
Return category, product, and price for products whose price equals the maximum price in their 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
products(category TEXT, product TEXT, price INTEGER)
Examples
Example 1
InputPython is max in Book
OutputPython and Mouse
The inner query recomputes the max for the current outer category.
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
InputPython is max in Book
Expected[["Book","Python",60],["Tool","Mouse",20]]
The inner query recomputes the max for the current outer category.
Hidden Test Categories
Empty or missing matchesDuplicate rows or tiesNULL values where the pattern commonly breaks