Business Analytics · Problem 89 of 118

Dormant Open Accounts

MediumBusiness AnalyticsBank data

Return account_id and balance_cents of every account with status = 'open' that has no transaction dated in 2026 (from 2026-01-01 onward). Sort by account_id.

Hint 1

Use NOT EXISTS with the date condition inside the subquery.

Hint 2

With a LEFT JOIN the date condition belongs in the ON, not in the WHERE.

Reference solution

SELECT a.account_id, a.balance_cents
FROM accounts AS a
WHERE a.status = 'open'
  AND NOT EXISTS (
    SELECT 1 FROM transactions AS t
    WHERE t.account_id = a.account_id AND t.txn_date >= '2026-01-01'
  )
ORDER BY a.account_id;

In an anti-join the extra condition describes which matches count, so it belongs in the ON (or in the NOT EXISTS subquery). If you put it in WHERE, rows with no match have NULL there and are thrown away, and the IS NULL test can never be true together with it. Dormant-account lists like this drive real outreach and compliance work.

Another way. The anti-join with the date condition in the ON clause.

SELECT a.account_id, a.balance_cents
FROM accounts AS a
LEFT JOIN transactions AS t ON t.account_id = a.account_id AND t.txn_date >= '2026-01-01'
WHERE a.status = 'open' AND t.txn_id IS NULL
ORDER BY a.account_id;