Retail · SQL
Grounding a revenue investigation with a precise October order count
Independent grading: 100/100(verify, opens in a new tab)
Problem
Meridian Retail (simulated retailer) was investigating a revenue gap in its October 2023 numbers, and the senior analytics team needed one verified fact before proceeding. The question put to me was simple: how many orders were placed in October 2023, in total, using the created_at column of the orders table?
What I did
Rather than using BETWEEN, which can behave unexpectedly with datetime values, I wrote the range as created_at >= '2023-10-01' AND created_at < '2023-11-01'. That upper boundary safely captures every timestamp through the last second of October 31st without excluding any rows. COUNT(*) was the right aggregate here because the task asks for a total row count, not a count of a specific non-null column. The query targets retail.orders as specified and returns a single, clearly named column.
Finding
The query returned 610 orders for October 2023, the exact figure the senior team needed to anchor their investigation.
Outcome
The senior analysts had a single verified order count to use as a reference point when reconciling the October revenue figures.
SELECT COUNT (*) AS total_october_orders FROM retail.orders WHERE created_at >= '2023-10-01' AND created_at < '2023-11-01';
The open upper boundary on 2023-11-01 ensures every timestamp within October, including 23:59:59 on the 31st, is included without truncation.
Next step
A useful next step would be to split that 610 figure by order status to see how many of those October orders ended as cancelled, returned, or refunded, which would speak directly to the revenue gap.
- datetime range filtering with >= and < boundary logic
- SQL COUNT(*) and COUNT(column) aggregation
- result column aliasing for readable output