Retail · SQL
Order status audit to support a CFO 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 clear picture of what order statuses existed in the orders table before any filtering could begin. The specific question was: how many distinct statuses are there, and how many orders carry each one?
What I did
To answer this, I wrote a single aggregation query grouping by the status column and counting all rows with COUNT(*), aliased as total_orders for readability at a CFO level. Sorting the output by total_orders descending meant the most common status appeared first, which made the distribution immediately scannable. Keeping the alias clean and the logic simple was deliberate: the output was meant to be a starting point for a wider investigation, not an end in itself.
Finding
The table contains 7 distinct statuses, and delivered dominates the distribution with 14,061 orders.
Outcome
The status inventory gave Nura a clear map of which order types to exclude when calculating net revenue, grounding the next stage of her discrepancy investigation.
SELECT status, COUNT(*) AS total_orders FROM retail.orders GROUP BY status ORDER BY total_orders DESC;
This query aggregates all orders by status and sorts them by volume descending, producing the full status inventory in a single pass.
Next step
A useful follow-on would be calculating the share of total revenue that each status represents, not just order count, to quantify the financial weight of cancelled and returned orders specifically.
- GROUP BY with COUNT and ORDER BY for frequency distributions
- Schema-qualified table references
- Multi-query diagnostic structuring across related tables