Retail · SQL
Profiling order statuses to support a CFO revenue 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 starting point before filtering any data. The first question was straightforward but essential: what order statuses exist in the orders table, and how many orders carry each one?
What I did
Before any revenue filtering could happen, the status taxonomy needed to be confirmed from the data itself rather than assumed. A GROUP BY query on the status column with COUNT(*) gave every distinct value and its frequency in one pass. Ordering by order_count descending meant the CFO could read the output top-to-bottom in priority order without any post-processing. Schema qualification on retail.orders and a clean alias on the count column were chosen to keep the query portable and the output self-explanatory.
Finding
All 7 distinct order statuses are present in the table, with delivered leading at 14,061 orders, giving Nura a confirmed taxonomy before any revenue analysis begins.
Outcome
The output gave the CFO a verified, priority-ordered status list to use as the foundation for subsequent revenue reconciliation queries.
SELECT STATUS, COUNT(*) AS Order_count FROM retail.orders GROUP BY status ORDER BY Order_count DESC;
Groups every row in retail.orders by its status value and counts occurrences, then sorts highest-count statuses first so the most operationally significant categories are immediately visible.
Next step
A useful follow-on would be breaking the status counts down by quarter to see whether the mix of cancelled or returned orders has shifted over the four-year date range.
- PostgreSQL GROUP BY aggregation
- Column aliasing for stakeholder-readable output
- Schema-qualified table references
- Single-pass multi-metric aggregation queries