Retail · SQL
Mapping all order statuses to support a revenue discrepancy investigation
Independent grading: 100/100(verify, opens in a new tab)
Problem
Nura Ibrahim, CFO at Meridian Retail (simulated retailer), flagged a revenue discrepancy and needed a reliable picture of the orders table before any filtering began. The first question was straightforward: what order statuses exist, and how many orders carry each one?
What I did
Before any investigative filtering made sense, a clean status inventory was needed. I queried retail.orders with GROUP BY status and COUNT(*) to count every order against its status value. Sorting by order_count DESC made the output immediately readable from the most common status downward, which is the natural reading order for an executive scanning the result.
Finding
The orders table contains 7 distinct statuses, with delivered dominating the distribution at 14,061 orders.
Outcome
Nura received a complete, ranked status map that confirmed no statuses were missing and gave her a reliable starting point for the revenue investigation.
SELECT status, COUNT(*) AS order_count FROM retail.orders GROUP BY status ORDER BY order_count DESC;
This query groups every row in retail.orders by its status value and counts them, returning all 7 statuses ranked from most to least common in a single scan.
Next step
A useful next step would be to cross-tabulate status against the order creation year to see whether the mix of cancelled or refunded orders has shifted over the four-year date range.
- GROUP BY aggregation
- Schema-qualified table references
- ORDER BY with NULLS LAST