Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Running Transaction Total with SQL

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

Your question is Running Transaction Total with SQL. 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

Ameriprise needs transaction-level activity metrics for clients using its financial data platforms. Write a PostgreSQL query that calculates each client's rolling transaction total across the thirty-day period ending on every transaction date.

Requirements

  1. Join transactions to clients and display the client name, using Unknown when a transaction has no matching client.
  2. Calculate a rolling sum of amount for each client, partitioned by client_id and ordered by transaction_date.
  3. Include transactions with negative amounts, zero amounts, and NULL amounts. NULL amounts should not contribute to the sum.
  4. Return results ordered by client, transaction date, and transaction ID. The thirty-day window is inclusive of the transaction date and the preceding 30 calendar days.

Schema

clients
ColumnTypeDescription
client_idPKINTEGERUnique Ameriprise client identifier
client_nameVARCHAR(100)Client display name
transactions
ColumnTypeDescription
transaction_idPKINTEGERUnique transaction identifier
client_idINTEGERClient associated with the transaction
transaction_dateDATETransaction posting date
amountNUMERIC(12,2)Transaction amount, including reversals
Tablesclientstransactions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results