Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Running Totals by Date

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

Your question is Running Totals by Date. 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

ValueMomentum's policy administration reporting feed needs a daily view of posted premium collections from active policy accounts. Write a PostgreSQL query that aggregates qualifying payments by date and calculates the cumulative collection total over time.

Requirements

  1. Join payments to policy accounts and include only accounts whose status is Active.
  2. Include only payments with payment_status = 'Posted'; exclude unmatched accounts and other payment statuses.
  3. Return one row per payment date with daily_collected and a chronological running_total. Dates containing only NULL payment amounts should remain in the result.

Schema

vm_policy_accounts
ColumnTypeDescription
account_idPKINTEGERUnique policy account identifier
account_numberVARCHAR(20)External policy account number
product_lineVARCHAR(40)Insurance product line
account_statusVARCHAR(20)Current account status
vm_premium_payments
ColumnTypeDescription
payment_idPKINTEGERUnique payment identifier
account_idINTEGERPolicy account receiving the payment
payment_dateDATEDate the payment was recorded
amountNUMERIC(12,2)Payment amount
payment_statusVARCHAR(20)Payment processing status
payment_methodVARCHAR(20)Payment method used
Tablesvm_policy_accountsvm_premium_payments
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results