SQL business case: the refund review
The head of sales thinks refunds are getting out of hand and wants facts by Friday. You have the orders, the customers and the order lines. Five queries take the question apart: the trend by month, the markets, the customers, the product categories, and the summary line for the top of the email.
Each step is a separate exercise, checked on the rows you see and again on changed data. Together they are the way an analyst actually answers an open question: one cut of the data at a time, with the same definition of a refund throughout.
Step 1: Refund rate per month
- Refund review, step 1: refund rate per monthThe head of sales thinks refunds are getting out of hand and wants facts by Friday. Start with the trend: for every month that has orders, return the month as text like 2025-01, the number of orders, the number of refunded orders and the refund rate in percent, rounded to 1 decimal. Count every order, whatever its status, in the number of orders.
Step 2: Refund rate per country
- Refund review, step 2: refund rate per countryNext question from the head of sales: is it one market? For every country that has orders, return the country, the number of orders, the number of refunded orders and the refund rate in percent, rounded to 1 decimal.
Step 3: Who gets the refunds
- Refund review, step 3: who gets the refundsIs it a few customers? For every customer with at least one refunded order, return the name, the number of refunded orders, the refunded amount and that customer's share of the total refunded amount in percent, rounded to 1 decimal.
Step 4: Refunded value per category
- Refund review, step 4: refunded value per categoryIs it a product problem? For every product category, return the category and the value of its order lines (quantity times price) on refunded orders. A category with nothing refunded must still appear, with 0.
Step 5: The summary line
- Refund review, step 5: the summary lineClose the review with the line that goes at the top of the email. Return one row: the number of orders, the number of refunded orders, the refund rate in percent rounded to 1 decimal, the refunded amount, and the refunded amount as a percentage of the paid amount, rounded to 1 decimal.
Other plans and cases
- 14-day SQL interview sprint (41)
- SQL for data analyst interviews (24)
- SQL for BI analyst interviews (21)
- SQL for data engineer interviews (24)
- Product analytics SQL in four sessions (12)
- SQL traps and time periods in three sessions (10)
- Window functions in six sessions (18)
- SQL on messy data: one work week (16)
- PostgreSQL features in four sessions (11)
- SQL business case: the payroll review (5)
- SQL business case: the monthly revenue report (4)
- SQL business case: customer value and segments (4)
- SQL business case: product performance (4)
- All exercises by level
Your first 8 exercises are free, with no account, from any plan or level. Progress is kept in this browser; a free account keeps it on every device.