Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Running Totals SQL Query

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

Your question is Running Totals SQL Query. 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

Resideo's Smart Home platform tracks customer purchases associated with its connected-home products. Write a PostgreSQL query that reports each customer's completed purchase total by date and the cumulative total through that date.

Requirements

  1. Include only purchases with status = 'completed' and a non-null purchase_date.
  2. Aggregate multiple purchases for the same customer on the same date into one daily total.
  3. Treat a null amount as zero.
  4. Calculate a running total that resets for each customer and order the final results by customer and date.

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
customer_nameVARCHAR(100)Customer display name
smart_home_purchases
ColumnTypeDescription
purchase_idPKINTUnique purchase identifier
customer_idINTCustomer associated with the purchase
purchase_dateDATEDate when the purchase was recorded
amountNUMERIC(10,2)Purchase amount
statusVARCHAR(20)Purchase processing status
Tablescustomerssmart_home_purchases
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results