Retail · SQL
Counting October 2023 orders to ground a revenue gap investigation
Independent grading: 100/100(verify, opens in a new tab)
Problem
The senior analysts at Meridian Retail (simulated retailer) were investigating a revenue gap in October 2023 and needed one verified fact before going further. The stakeholder asked me to confirm the total number of orders placed during that calendar month using the orders table and its created_at column.
What I did
To avoid any edge case where a timestamp on 31 October could be excluded or included incorrectly, I used a half-open date interval: created_at >= '2023-10-01' AND created_at < '2023-11-01'. This pattern captures every row in the month regardless of the time component on the final day. COUNT(*) was the right aggregate here because every row in the orders table represents one order, so no column filtering was needed.
Finding
The query returned 610 orders for October 2023, matching the verified ground truth exactly.
Outcome
The senior analysts had a confirmed, reproducible order count to anchor their revenue gap investigation.
SELECT COUNT(*) FROM orders WHERE created_at >= '2023-10-01' AND created_at < '2023-11-01';
The half-open interval on created_at ensures the full month is captured without relying on date-truncation functions, making the filter portable across different SQL dialects.
Next step
A useful next step would be breaking the 610 orders down by order status, to check whether cancellations or returns contributed to the revenue gap the seniors were tracking.
- COUNT(*) and WHERE filtering in SQL
- Date-range filtering with half-open interval pattern in SQL