Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL for Past-Due Accounts

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is SQL for Past-Due Accounts. Start with the requirements and the three tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Extra Space Storage operations managers need a location-level view of customer accounts with unpaid balances more than 30 days past their invoice due date. Using February 15, 2025 as the reporting date, write a PostgreSQL query that identifies these accounts and summarizes their exposure by store location.

Requirements

  1. Include only active accounts with a positive unpaid balance and a due date more than 30 days before the reporting date.
  2. Group results by Extra Space Storage store location.
  3. Return the number of overdue accounts, a comma-separated list of account numbers, and the total outstanding balance.
  4. Sort locations alphabetically.

Representative Data

The supplied sample data includes multiple invoices per account, fully paid invoices, a boundary due date, closed accounts, missing payments, and unmatched records.

Schema

stores
ColumnTypeDescription
store_idPKINTUnique Extra Space Storage store identifier
locationVARCHAR(100)Store city and state
customer_accounts
ColumnTypeDescription
account_idPKINTUnique customer account identifier
store_idINTStore assigned to the customer account
account_numberVARCHAR(20)Customer-facing account number
customer_nameVARCHAR(100)Customer name on the account
statusVARCHAR(20)Current account status
invoices
ColumnTypeDescription
invoice_idPKINTUnique invoice identifier
account_idINTCustomer account billed by the invoice
due_dateDATEDate payment was due
amount_dueNUMERIC(10,2)Original invoice amount
amount_paidNUMERIC(10,2)Amount paid against the invoice
Tablesstorescustomer_accountsinvoices
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results