WHERE Clause & Filtering SQL Topic exerciseMediumVerified answerSQLite + PostgreSQL + MySQL + SQL Server live · 1 guided

Extract February Payment Events

Find completed payment events that occurred during February 2025.

  • Filtering
  • Sorting

Exercise brief

Understand the request

Payments operations analyst The monthly reconciliation needs completed payment events from February 2025 only.

Return completed payment events that occurred during February 2025.

Return

  • Return event_id, account_id, occurred_at in this exact left-to-right order.

Constraints

  • Use a half-open month: include February 1 at midnight and exclude March 1 at midnight.

Data you will use

Review the relevant tables before deciding how to join, filter, or aggregate them.

filter_events

  • event_idINTEGER
  • account_idINTEGER
  • occurred_atDATETIME

Hints, when you need them

Open one clue at a time so you still do the reasoning.

Hint 1

Represent a whole month as a half-open interval: include its first instant and exclude the first instant of the next month.

Hint 2

Filter event type and status, then apply `>=` to the February boundary and `<` to the March boundary.

Hint 3

SELECT event_id, account_id, occurred_at FROM filter_events WHERE event_type = /* event type */ AND status = /* final status */ AND occurred_at /* inclusive start */ '2025-02-01 00:00:00' AND occurred_at /* exclusive end */ '2025-03-01 00:00:00' ORDER BY occurred_at;

Verified SQL answer

Attempt the problem first, then compare structure and reasoning—not just syntax.

Reveal solution and explanation
SELECT event_id, account_id, occurred_at FROM filter_events WHERE event_type = 'payment' AND status = 'completed' AND occurred_at >= '2025-02-01 00:00:00' AND occurred_at < '2025-03-01 00:00:00' ORDER BY occurred_at;

Why this works

The half-open interval includes midnight on February 1 and every later February timestamp, but excludes exactly midnight on March 1. The fixture contains rows immediately before, at, and after those boundaries, plus wrong-type and failed events. ISO timestamp literals work in the executable engines; Oracle uses explicit TIMESTAMP literals.

Success check

Only completed payment events inside the February interval are returned in timestamp order.

Expected result

Use this output to verify values, aliases, ordering, and row count.

event_idaccount_idoccurred_at
21012025-02-01 00:00:00
111102025-02-13 23:59:59
31022025-02-14 00:00:00
41032025-02-14 12:30:00
51042025-02-14 23:59:59
101092025-02-15 00:00:00
61052025-02-28 23:59:59

Learn the concepts behind this answer

Strengthen your understanding with these targeted learning topics:

Continue practicing

SQL Practice Online

Open the interactive workspace and practice across SQL topics.