Find the Latest Balance for a Bank Account

Read the full interview experience this question came from →

Quick Overview

Query the latest dated bank-account balance using both bank and account identifiers while handling records across months and years.

Find the Latest Balance for a Bank Account

Company: Stripe

Role: Software Engineer

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Technical Screen

Write a PostgreSQL query that returns the latest reported balance for one bank account. ### Tables `bank_balances(bank_name text, account_name text, start_date date, end_date date, balance numeric(18,2))` `requested_account(bank_name text, account_name text)` contains exactly one row. ### Rules - Match both bank name and account name exactly. Account names are text identifiers and may contain leading zeros. - For this exercise, latest means greatest `end_date`; each bank/account pair has at most one row with a given end date. - Every field is non-null, and `start_date <= end_date`. - Records may span different months and years. Dates are typed dates, not strings to compare lexicographically. ### Output Return one column named `balance` for the latest matching record. If the requested account has no record, return no rows. The end-date definition and missing-account behavior are explicit exercise conventions. ### Example `bank_balances`: | bank_name | account_name | start_date | end_date | balance | |---|---|---|---|---:| | Harbor | 001234 | 2021-12-01 | 2021-12-31 | 150.00 | | Harbor | 001234 | 2019-05-01 | 2019-05-31 | 200.00 | | Bay | 001234 | 2022-01-01 | 2022-01-31 | 300.00 | `requested_account`: `('Harbor', '001234')` Expected output: | balance | |---:| | 150.00 |

Overview: Query the latest dated bank-account balance using both bank and account identifiers while handling records across months and years.

Read the full Stripe Software Engineer interview experience this question came from

|Home/Data Manipulation (SQL/Python)/Stripe
Stripe logo
Stripe
Aug 31, 2026
mediumSoftware EngineerTechnical ScreenData Manipulation (SQL/Python)
0
0

Write a PostgreSQL query that returns the latest reported balance for one bank account.

Tables

bank_balances(bank_name text, account_name text, start_date date, end_date date, balance numeric(18,2))

requested_account(bank_name text, account_name text) contains exactly one row.

Rules

  • Match both bank name and account name exactly. Account names are text identifiers and may contain leading zeros.
  • For this exercise, latest means greatest end_date ; each bank/account pair has at most one row with a given end date.
  • Every field is non-null, and start_date <= end_date .
  • Records may span different months and years. Dates are typed dates, not strings to compare lexicographically.

Output

Return one column named balance for the latest matching record. If the requested account has no record, return no rows. The end-date definition and missing-account behavior are explicit exercise conventions.

Example

bank_balances:

bank_nameaccount_namestart_dateend_datebalance
Harbor0012342021-12-012021-12-31150.00
Harbor0012342019-05-012019-05-31200.00
Bay0012342022-01-012022-01-31300.00

requested_account: ('Harbor', '001234')

Expected output:

balance
150.00
Loading comments...