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 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.
| Column | Type | Description |
|---|---|---|
| customer_idPK | INT | Unique customer identifier |
| customer_name | VARCHAR(100) | Customer full name |
| segment | VARCHAR(50) | Customer segment label |
| Column | Type | Description |
|---|---|---|
| transaction_idPK | INT | Unique transaction identifier |
| customer_id | INT | Customer identifier associated with the transaction |
| transaction_date | DATE | Date the transaction was recorded |
| amount | DECIMAL(10,2) | Transaction amount, which may be positive, zero, or negative |
| channel | VARCHAR(50) | Transaction channel |