Back to Practice
#0390
Refund Adjusted Revenue
MediumSQL24 min20 XP
Problem
Return net_revenue as total order amount minus total refunded amount.
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); refunds(refund_id INTEGER, order_id INTEGER, amount INTEGER)
Examples
Example 1
Input150 gross revenue and 20 refunded
Output130
COALESCE protects the subtraction when there are no refunds.
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
Input150 gross revenue and 20 refunded
Expected[[130]]
COALESCE protects the subtraction when there are no refunds.
Hidden Test Categories
Empty or missing matchesDuplicate rows or tiesNULL values where the pattern commonly breaks