Back to Practice
#0387

Products With Price Increase

MediumSQL24 min20 XP

Problem

Return product and changed_on for rows where price increased from the previous price for that product.

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

price_history(product TEXT, changed_on TEXT, price INTEGER)

Examples

Example 1
InputBook price rises from 10 to 12
OutputBook on Jan 5

LAG exposes the previous price for comparison.

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
InputBook price rises from 10 to 12
Expected[["Book","2026-01-05"]]

LAG exposes the previous price for comparison.

Hidden Test Categories
Empty or missing matchesDuplicate rows or tiesNULL values where the pattern commonly breaks