Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Running Total Sales by Date

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

Your question is Running Total Sales 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

Arcesium QA needs to validate cumulative sales balances shown for active portfolios. Sales can have multiple posted records on the same settlement date, including corrections and null amounts.

Write a PostgreSQL query that calculates a running total of posted sales by settlement date for each active portfolio.

Requirements

  1. Join portfolio_sales to portfolios and include only portfolios with portfolio_status = 'active'.
  2. Include only sales with sale_status = 'posted'.
  3. Aggregate sales to one row per portfolio and settlement date, treating a date containing only null amounts as zero.
  4. Calculate the cumulative sales total per portfolio in chronological order.

Schema

portfolios
ColumnTypeDescription
portfolio_idPKINTUnique portfolio identifier.
portfolio_nameVARCHAR(100)Human-readable Arcesium portfolio name.
portfolio_statusVARCHAR(20)Current portfolio lifecycle status.
portfolio_sales
ColumnTypeDescription
sale_idPKINTUnique sales record identifier.
portfolio_idINTPortfolio associated with the sale.
settlement_dateDATEDate on which the sale settled.
sale_amountDECIMAL(14,2)Signed monetary amount of the sale.
sale_statusVARCHAR(20)Processing status of the sale record.
Tablesportfoliosportfolio_sales
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results