Back to Practice
#0388

First Order Amount Per User

MediumSQL24 min20 XP

Problem

Return user_id, order_date, and amount for each user’s first order.

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

orders(order_id INTEGER, user_id INTEGER, order_date TEXT, amount INTEGER)

Examples

Example 1
Inputuser 1 first order is Jan 1
Outputuser 1 Jan 1 amount 30

ROW_NUMBER keeps the full first-order row, not just the minimum date.

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
Inputuser 1 first order is Jan 1
Expected[[1,"2026-01-01",30],[2,"2026-01-02",40]]

ROW_NUMBER keeps the full first-order row, not just the minimum date.

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