Back to Practice
#0322
Revenue After Optional Discounts
EasySQL15 min10 XP
Problem
Return order_id and net_amount as amount minus discount, treating NULL discount as 0.
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, amount INTEGER, discount INTEGER)
Examples
Example 1
Inputone NULL discount
Output100 and 85
COALESCE turns NULL discount into 0 before subtraction.
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
Inputone NULL discount
Expected[[1,100],[2,85]]
COALESCE turns NULL discount into 0 before subtraction.
Hidden Test Categories
Empty or missing matchesDuplicate rows or tiesNULL values where the pattern commonly breaks