Retail · SQL
Enumerating all 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 clean starting point before any filtering began. The specific question was: what order statuses exist in the orders table, and how many orders carry each one? Understanding the full status landscape was a prerequisite for every reconciliation step that followed.
What I did
A single aggregation query using GROUP BY status with COUNT(*) aliased as order_count gave a precise enumeration of every status present in the table. Ordering the result by order_count DESC meant the most frequent status surfaced immediately, making the output readable without any post-processing. Because the retail search path was already set in the session, no schema prefix was required, keeping the query concise.
Finding
All 7 distinct order statuses were confirmed: delivered, shipped, cancelled, confirmed, returned, pending, and refunded, with delivered accounting for 14,061 orders as the dominant status.
Outcome
Nura received a complete, ranked status map of the orders table, giving her a reliable foundation before any revenue filters were applied.
SELECT status, COUNT(*) AS order_count FROM orders GROUP BY status ORDER BY order_count DESC;
This query groups every row in the orders table by its status value and counts them, then sorts the result so the highest-volume status appears first.
Next step
A useful next step would be to break the delivered count down by month to check whether the status distribution has shifted over the four-year date range.
- GROUP BY aggregation with COUNT and SUM
- Custom ORDER BY CASE for business-logic sorting
- Schema-qualified table references in PostgreSQL