Skip to content
RED SAGSkills
medium10 pts · first answer countschurn-preventionsql

SQL: active last month, not this month

The table `activity(customer_id, month)` has one row per customer per active month. Which query lists customers active in January 2026 but not in February 2026?

-- A
SELECT j.customer_id
FROM activity j
LEFT JOIN activity f
  ON f.customer_id = j.customer_id AND f.month = '2026-02'
WHERE j.month = '2026-01' AND f.customer_id IS NULL;

-- B
SELECT customer_id FROM activity
WHERE month = '2026-01' AND month <> '2026-02';

-- C
SELECT j.customer_id
FROM activity j
JOIN activity f ON f.customer_id = j.customer_id
WHERE j.month = '2026-01' AND f.month = '2026-02';

-- D
SELECT customer_id FROM activity
WHERE month IN ('2026-01', '2026-02');
Choose one answer

Discussion 0

Join free to post in the discussion.

Related questions