SQLで日付範囲検索をしたら終了日当日のデータが漏れた場合

datetime型を日付で <= 比較すると、その日の0時として扱われ、当日の日中が漏れる。

-- NG: 2026-11-20 15:30 が漏れる
where created_at <= '2026-11-20'

終了日は「翌日の0時より前」で絞る。

where created_at >= '2026-11-20'
  and created_at <  '2026-11-21'

23:59:59 以下にする書き方だと、小数秒を持つ値が漏れることがある。