Skip to content

Customers with savings but no open checking account

MediumFull bankRows with no matchJoinsNULL handling14 min2 hidden datasets

The task

The bank wants to offer a checking account to customers who save with them but do not have one to spend from.

An account is open when closed_on is NULL. Find the customers who have at least one open savings account and no open checking account. A customer whose only checking account has been closed counts as having none, and so does a customer who never had one. Other account types do not matter for the checking test.

Return customer_id, full_name and open_savings (their number of open savings accounts). Sort by open_savings descending, then customer_id.

Expected output

customer_idfull_nameopen_savings
  • Sorted by open_savings descending, then customer_id ascending.
  • Checked on the sample and on 2 hidden datasets. How grading works

Tables Digital bank · click a name to insert it

customers70 rows in the sample

One row per customer. Key: customer_id.

intUnique id.
textName.
dateDay they became a customer.
textretail, premium or business.
accounts126 rows in the sample

One row per account. A customer can have several. Key: account_id.

intUnique id.
intOwner.
textchecking, savings or credit.
dateOpening day.
dateClosing day. NULL while open.
transactions9,906 rows in the sample

One row per posted transaction. Positive amounts are money in, negative are money out. Key: txn_id.

bigintUnique id.
intThe account.
timestampWhen it posted (UTC).
numeric(12,2)Signed amount, USD.
textsalary, rent, groceries, dining, travel, transfer, fees or refund.
textMerchant name. NULL for salary, transfers and fees.

Related questions

Loading the editor and PostgreSQL