Problems / Relative Date Buckets / Editorial
DATE_DIFF('day', order_date, <reference>)
<= 6
<= 29
BETWEEN
An N-day window contains days 0 through N-1 — "last 7 days" ends at days_ago = 6, not 7. Off-by-one bucket edges are the classic silent dashboard bug: nothing errors, one day of orders just lands in the wrong bucket forever. Anchoring to a *fixed* reference date (rather than CURRENT_DATE) is the other discipline this problem models: deterministic queries are testable queries.
0
N-1
days_ago = 6
CURRENT_DATE
Solve Relative Date Buckets yourself →