Using 2026-06-30 as "today": return the customerid and name of customers who have at least one account but made no…
SQLLevel: IntermediateCore interview patterns
Using 2026-06-30 as "today": return the customer_id and name of customers who have at least one account but made no transactions in the last 30 days (i.e. after 2026-05-31).
Table definitions (from the source exercise):
CREATE TABLE customers(customer_id INTEGER PRIMARY KEY, name TEXT, city TEXT, signup_date TEXT, credit_score INTEGER);
CREATE TABLE accounts(account_id INTEGER PRIMARY KEY, customer_id INTEGER, product_type TEXT, open_date TEXT, credit_limit INTEGER, status TEXT);
CREATE TABLE transactions(transaction_id INTEGER PRIMARY KEY, account_id INTEGER, transaction_date TEXT, amount REAL, merchant_category TEXT);
Hints
- Write an interleaving of two concurrent operations.
- Which observations does the isolation level permit, and what happens on a mid-operation failure?
Answer
Approach: LEFT JOIN transactions with the date condition inside the ON clause (not WHERE), then HAVING COUNT of transactions = 0. Or NOT EXISTS.
SELECT c.customer_id, c.name
FROM customers c
JOIN accounts a ON a.customer_id = c.customer_id
LEFT JOIN transactions t ON t.account_id = a.account_id
AND t.transaction_date > '2026-05-31'
GROUP BY c.customer_id, c.name
HAVING COUNT(t.transaction_id) = 0;
The source uses SQLite with a MySQL compatibility layer. Date and string functions are dialect dependent; the query is preserved as published.
Source and licence: SQL Practice Lab — Ebrahim Sharifi · MIT