Skip to course content
Free SQL course

SQL for Data Analysis and AI

Module 08 Summary

The idea this module was built around

Date filtering is where careful analysts lose data without noticing, because a missing day looks exactly like a slow day. Nothing errors. The chart just dips.

What you can now do

The trap this module removed

BETWEEN '2026-06-01' AND '2026-06-15' on a TIMESTAMP column includes 15 June only at 00:00:00. No order was placed at exactly midnight, so all 33 orders on 15 June disappear: BETWEEN returns 472 where the half-open form returns 505. An entire day vanished from a two-week figure, and the output looked perfectly normal.

The convention to adopt permanently

Write every date range as >= start AND < next_start. It reads slightly worse. It is correct for every period length, needs no special handling for the final day, and behaves the same whether the column stores a date or a timestamp.

Figures worth remembering

The dataset spans 2026-06-01 to 2026-06-30 - 30 days, 1,000 orders, averaging 33.33 per day. The first three days hold 102 orders; 30 June alone holds 33.

Before you move on

Find a date filter in something you maintain and check whether it uses BETWEEN on a timestamp column. If it does, you have very likely been losing the last day of every period it reports.