Day 3 — Answer Five Business Questions with SQL
Scenario
The e-commerce leadership team has agreed on KPI definitions, but the monthly business review still raises unanswered questions. Revenue has moved unevenly across regions, order volume is unclear, repeat purchasing may be weakening, and some product categories have rising returns.
You have been asked to produce a reliable SQL analysis before the next review. Your job is not just to make queries run: every result must have a clear grain, correct joins, and a business interpretation.
Dataset contract
Use a public or synthetic e-commerce dataset and map it to the following logical tables. If your source uses different names, document the mapping.
| Table | Expected grain | Required fields |
|---|---|---|
orders |
One row per order | order_id (PK), customer_id, order_date, order_status, region_id |
order_items |
One row per order line | order_item_id (PK), order_id, product_id, quantity, unit_price, discount_amount, unit_cost |
customers |
One row per customer | customer_id (PK), signup_date, acquisition_channel |
products |
One row per product | product_id (PK), product_name, category |
regions |
One row per region | region_id (PK), region_name |
returns |
One row per return event | return_id (PK), order_item_id, return_date, quantity_returned, refund_amount, return_reason |
Analysis rules
- Use completed orders only. Exclude cancelled and pending orders.
- Gross sales =
quantity × unit_price. - Net sales = gross sales − line-level
discount_amount. - Treat refunds as a separate measure. Do not silently subtract refunds from net sales.
- A return can have multiple events for one order line. Aggregate returns to the order-line grain before joining them to sales.
- Define any additional assumptions and keep currency and date treatment consistent.
- Use PostgreSQL or clearly state another SQL dialect.
Your mission
Answer these five business questions with SQL.
1. Is sales performance improving?
Create a monthly trend showing:
- Gross sales
- Discounts
- Net sales
- Month-over-month net sales growth
State how you handle months with zero or missing sales.
2. What is happening to order volume and basket value?
For each month and region, calculate:
- Completed order count
- Unique purchasing customers
- Net sales
- Average order value (AOV)
Make sure an order with multiple line items is counted once.
3. Are customer cohorts coming back?
Build a monthly cohort-retention table.
- Assign each customer to the month of their first completed order.
- Calculate the number of customers from each cohort who placed at least one completed order in each subsequent month.
- Show cohort size, retained customers, month number since acquisition, and retention percentage.
Use first purchase month—not signup month—as the cohort definition. Explain how you treat incomplete or partial months.
4. Which product categories have a returns problem?
By product category, calculate:
- Units sold
- Units returned
- Unit return rate
- Refund value
Avoid inflating sales or return totals when joining order lines to multiple return events. State whether your return rate is unit-based or order-based.
5. Where should leadership investigate first?
Create a monthly region-by-category view containing net sales, order count, and unit return rate. Compare each segment with the previous month.
Identify two region/category combinations that deserve investigation. For each one, state whether the evidence points more strongly to a sales-volume decline, weaker basket value, or worsening returns. Do not claim causation from a descriptive query alone.
Required deliverables
- One SQL file containing all five numbered queries, with comments and readable CTEs.
- Five result extracts (CSV or screenshots), one for each question.
- Data and grain notes describing table keys, join paths, filters, and any source-to-schema mapping.
- Validation checks for duplicate keys, order counts, sales totals, and return quantities. Explain any reconciliation differences.
- Five business interpretations—one per query—plus a short executive summary (maximum 150 words) naming the two segments you would investigate first.
Submission format
Submit in this order:
- SQL file or repository link
- Dataset source and SQL dialect
- Table-grain and join notes
- Results for Questions 1–5
- Validation checks and caveats
- Executive summary (150 words maximum)
Constraints
- Do not copy a finished query or dashboard.
- Do not hide join duplication with
DISTINCT; fix the grain and join logic. - Do not use confidential employer or customer data.
- Keep the SQL reproducible: another analyst should be able to run it and understand the assumptions.
Quality bar: Correct totals matter more than clever syntax. Every query must answer a business question, preserve the intended grain, and support a defensible interpretation.