Retail · SQL
Mapping order statuses to support a revenue discrepancy investigation
Independent grading: 97/100(verify, opens in a new tab)
Problem
Nura Ibrahim, CFO of Meridian Retail (simulated retailer), flagged a revenue discrepancy and needed a clear picture of the orders table before any filtering began. The first question was simple but foundational: what order statuses exist, and how many orders carry each one?
What I did
A single GROUP BY status query with COUNT(*) gave a complete frequency table across all statuses. Ordering the result by order_count DESC meant the most common statuses appeared first, making the output immediately scannable without any post-processing. The query was kept short deliberately, because at this stage the goal was orientation, not analysis.
Finding
Seven distinct statuses exist: delivered, shipped, cancelled, confirmed, returned, pending, and refunded. Delivered leads with 14,061 orders, and the three reversal statuses, cancelled (2,007), returned (1,154), and refunded (949), together account for 4,110 orders that would need to be excluded from any net revenue figure.
Outcome
Nura had a clean, ranked status inventory to anchor the rest of the investigation and a first signal that roughly 4,110 orders carry reversal statuses relevant to net revenue.
SELECT status, COUNT(*) AS order_count FROM orders GROUP BY status ORDER BY order_count DESC;
Groups every row in the orders table by its status value and counts occurrences, ordering the result so the highest-volume statuses appear first.
Next step
A useful follow-up would be to break the reversal statuses down by month to check whether cancellations and returns spike in particular periods, which would tell Nura whether the gap is seasonal or structural.
- GROUP BY with COUNT(*) for frequency distributions
- ORDER BY for ranked output
- WHERE clause filtering on status and date