Retail · SQL
Counting October 2023 orders to ground a revenue investigation
Independent grading: 100/100(verify, opens in a new tab)
Problem
Meridian Retail (simulated retailer) was investigating a revenue gap in October 2023, and a senior analyst needed one verified fact before the deeper work could begin: the exact number of orders placed that month. The question was simple but the stakes were real, because an incorrect count would undermine every calculation built on top of it.
What I did
Rather than filtering on month and year functions, I used a half-open date range in the WHERE clause, setting the lower bound at 2023-10-01 and the upper bound at 2023-11-01 with a strict less-than. This approach safely captures any timestamp that falls late in the day on 31 October without needing to account for time components explicitly. COUNT(*) counts every row regardless of column nullability, which is correct for an order count, and I aliased the result as total_orders so the output column is self-explanatory.
Finding
The query returned 610 orders for October 2023, matching the verified ground truth exactly.
Outcome
The senior analyst received a confirmed baseline count to anchor the revenue gap investigation.
SELECT COUNT(*) AS total_orders FROM orders WHERE created_at >= '2023-10-01' AND created_at < '2023-11-01';
The half-open interval ensures no late-day October records are dropped due to a time component on the created_at timestamp.
Next step
A useful follow-up would be to break the 610 orders down by status to see how many were cancelled, returned, or refunded within that month, which would let the senior analyst move directly from the count to a net revenue estimate.
- Half-open date range filtering in SQL WHERE clauses
- COUNT(*) and descriptive column aliasing
- SQL GROUP BY aggregation with ORDER BY