Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Customer Transaction Running Totals

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

Your question is Customer Transaction Running Totals. Start with the requirements and the two 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

You are given transaction data and customer reference data from an internal analytics environment such as McKinsey's Wave. Write a PostgreSQL query that returns each valid customer's transactions in chronological order along with a running total of transaction amounts over time. The running total should restart for each customer, and transactions tied on the same date should be ordered by transaction ID so the cumulative values are deterministic. Exclude transactions that do not map to a known customer.

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
customer_nameVARCHAR(100)Customer full name
segmentVARCHAR(50)Customer segment label
transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
customer_idINTCustomer identifier associated with the transaction
transaction_dateDATEDate the transaction was recorded
amountDECIMAL(10,2)Transaction amount, which may be positive, zero, or negative
channelVARCHAR(50)Transaction channel
Tablescustomerstransactions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results