Filter records for the month of October
Filed under Barclays
Free read 1 of 3Determine if the column is a string or a proper DATE/DATETIME type.
The question
Write an SQL query to select all records from a table where the date column falls within the month of October.
Constraints
- Assume a table named 'records' with a column 'created_at' of type DATE or DATETIME.
- The solution should be database-agnostic or specify the dialect (e.g., MySQL, PostgreSQL).
Examples
- Input
- Table: records (id, created_at), Row: (1, '2023-10-15')
- Output
- 1
- Why
- The date falls in October, so it is selected.
Approach
Determine if the column is a string or a proper DATE/DATETIME type.
Use standard functions like MONTH(date_col) = 10 or EXTRACT(MONTH FROM date_col) = 10.
For performance, use a range: date_col >= '2023-10-01' AND date_col < '2023-11-01' to allow index scans.
Tips
- What they are testing: Tests verify if the query correctly handles different years and boundary dates (Oct 1st vs Oct 31st).
- Common mistake: Using LIKE '%-10-%' is inefficient as it prevents index usage and may match incorrect patterns.
Related Barclays questions
Collected from public candidate posts and coding forums. Updated Nov 2026.