Retail · SQL
Profiling order statuses to support a revenue discrepancy investigation
Independent grading: 97/100(verify, opens in a new tab)
Problem
Meridian Retail (simulated retailer) CFO Nura Ibrahim flagged a revenue discrepancy and needed a baseline picture of the orders table before filtering could begin. The specific question was: what distinct order statuses exist, and how many orders carry each one?
What I did
A single SELECT with COUNT(*) and GROUP BY status against retail.orders produced the full status breakdown in one pass. Ordering by the count descending was a deliberate choice so the dominant status would appear at the top without any additional sorting step. The explicit schema prefix retail.orders was kept in place even though the search path was already set, to keep the query unambiguous in any session context.
Finding
All 7 distinct statuses were present, with delivered accounting for 14,061 orders as the dominant status, and cancellations, returns, and refunds visible as the revenue-impacting tail.
Outcome
The output gave Nura a ranked, complete status map to guide the next filtering step in her investigation, with no manual counting or pivoting required.
Next step
A useful follow-on would be to calculate the naira value associated with each status, so the revenue impact of cancelled, returned, and refunded orders can be compared directly rather than just by order count.
- SQL GROUP BY with COUNT(*) aggregation
- ORDER BY on aggregated column for ranked output
- Explicit schema prefix usage in PostgreSQL