Reconcile Monthly Bank-Account Balances Across Two Datasets

Read the full interview experience this question came from →

Quick Overview

Compare bank-account balances for a target calendar month, report match status, and distinguish missing comparison records from zero balances.

Reconcile Monthly Bank-Account Balances Across Two Datasets

Company: Stripe

Role: Software Engineer

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Technical Screen

Write a PostgreSQL query that compares monthly bank-account balances from two imported datasets and marks each account in the first dataset as matching or not matching the second. ### Tables Both `primary_balances` and `comparison_balances` have columns: `bank_name text, account_name text, start_date date, end_date date, balance numeric(18,2)` `report_month(month_start date)` contains exactly one row whose value is the first day of the target month. ### Exercise Conventions - A record belongs to the calendar month containing its `end_date`. - In each input table, there is at most one record per bank/account/end-date month. All fields are non-null, and `start_date <= end_date`. - Report each primary record in the target month. Accounts appearing only in the comparison table are outside this report. - Match records by bank name, account name, and target month, even if the two end dates within that month differ. - A primary record is `Match` only when a comparison record exists and the two numeric balances are equal. Otherwise it is `Not Match`. - Do not sum records across years or treat a missing comparison record as a zero balance. These schema and missing-record conventions make the monthly reconciliation task precise. ### Output Return `bank_name`, `account_name`, `end_date`, `balance`, and `match_status`. The end date and balance come from the primary record. Sort by bank name and then account name using `COLLATE "C"` for deterministic text order. ### Example Target month: `2021-12-01`. `primary_balances`: | bank_name | account_name | start_date | end_date | balance | |---|---|---|---|---:| | Bay | 02 | 2021-12-01 | 2021-12-31 | 300.00 | | Harbor | 01 | 2021-12-01 | 2021-12-31 | 150.00 | | Harbor | 01 | 2020-12-01 | 2020-12-31 | 999.00 | `comparison_balances`: | bank_name | account_name | start_date | end_date | balance | |---|---|---|---|---:| | Bay | 02 | 2021-12-01 | 2021-12-31 | 250.00 | | Harbor | 01 | 2021-12-01 | 2021-12-30 | 150.00 | Expected output: | bank_name | account_name | end_date | balance | match_status | |---|---|---|---:|---| | Bay | 02 | 2021-12-31 | 300.00 | Not Match | | Harbor | 01 | 2021-12-31 | 150.00 | Match |

Overview: Compare bank-account balances for a target calendar month, report match status, and distinguish missing comparison records from zero balances.

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 compares monthly bank-account balances from two imported datasets and marks each account in the first dataset as matching or not matching the second.

Tables

Both primary_balances and comparison_balances have columns:

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

report_month(month_start date) contains exactly one row whose value is the first day of the target month.

Exercise Conventions

  • A record belongs to the calendar month containing its end_date .
  • In each input table, there is at most one record per bank/account/end-date month. All fields are non-null, and start_date <= end_date .
  • Report each primary record in the target month. Accounts appearing only in the comparison table are outside this report.
  • Match records by bank name, account name, and target month, even if the two end dates within that month differ.
  • A primary record is Match only when a comparison record exists and the two numeric balances are equal. Otherwise it is Not Match .
  • Do not sum records across years or treat a missing comparison record as a zero balance.

These schema and missing-record conventions make the monthly reconciliation task precise.

Output

Return bank_name, account_name, end_date, balance, and match_status. The end date and balance come from the primary record. Sort by bank name and then account name using COLLATE "C" for deterministic text order.

Example

Target month: 2021-12-01.

primary_balances:

bank_nameaccount_namestart_dateend_datebalance
Bay022021-12-012021-12-31300.00
Harbor012021-12-012021-12-31150.00
Harbor012020-12-012020-12-31999.00

comparison_balances:

bank_nameaccount_namestart_dateend_datebalance
Bay022021-12-012021-12-31250.00
Harbor012021-12-012021-12-30150.00

Expected output:

bank_nameaccount_nameend_datebalancematch_status
Bay022021-12-31300.00Not Match
Harbor012021-12-31150.00Match
Loading comments...