Retail · SQL
Mapping order status distribution to frame a revenue 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 starting point before any filtering was applied. The specific question was: what distinct order statuses exist in the orders table, and how many orders carry each one?
What I did
A GROUP BY on the status column paired with COUNT(*) captures every distinct value in a single pass, without needing to know the statuses in advance. Ordering the result by the count descending meant the dominant status would surface immediately, reducing the time Nura needed to scan the output. The alias Total_order was chosen to make the column self-explanatory in a shared result set.
Finding
Seven distinct statuses exist: delivered, shipped, cancelled, confirmed, returned, pending, and refunded. Delivered is the dominant status, with 14,061 orders.
Outcome
Nura received a complete, ranked status inventory she could use as the foundation for all subsequent filtering in the revenue investigation.
SELECT status, count(*) as Total_order FROM orders GROUP BY status ORDER BY Total_order DESC ;
This query groups every row in the orders table by its status value, counts occurrences, and sorts descending so the highest-volume status appears first.
Next step
A useful next step would be to calculate each status as a percentage share of total orders, so the relative weight of revenue-excluding statuses is immediately visible without manual arithmetic.
- GROUP BY with COUNT(*) for frequency aggregation
- ORDER BY on aggregated columns for readable ranking
- Descriptive column aliasing for stakeholder-ready output