Management & CommerceVery hardMBA Placement · Data Analyst · SQL test

orders.created_at is a TIMESTAMP; a bare date literal is read as midnight. Rows: 2024-03-01 09:00, 2024-03-15 10:00, 2024-03-31 18:45 and 2024-04-01 08:00. How many rows does WHERE created_at BETWEEN '2024-03-01' AND '2024-03-31' return, and what is the safe filter for March?

  1. A. 3; BETWEEN covers the whole of 31 March
  2. B. 3; use BETWEEN '2024-03-01' AND '2024-04-01'
  3. C. 4; BETWEEN includes the next day's midnight
  4. D. 2; use >= '2024-03-01' AND < '2024-04-01'

Correct answer: D. 2; use >= '2024-03-01' AND < '2024-04-01'

The upper bound is 2024-03-31 00:00, so the 18:45 order on 31 March is missed: 2 rows. A half-open range (>= start AND < next month) catches every timestamp in March; ending BETWEEN at '2024-04-01' would wrongly include an order placed exactly at midnight on 1 April.

More Operations, Supply Chain & Business Analytics questions

Exams that ask this topic