Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Running Total SQL

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

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

The Tata Consultancy Services North America sales team tracks TCS BaNCS implementation revenue across client accounts. Write a PostgreSQL query that reports monthly North American sales and the cumulative sales total through each month.

Requirements

  1. Join sales transactions to client accounts and include only accounts in the North America region.
  2. Restrict transactions to January through April 2025 and aggregate sales by calendar month.
  3. Calculate a running total of monthly sales in chronological order using a window function.
  4. Return the month as YYYY-MM, monthly sales, and the running total, ordered from earliest to latest month.

Schema

tcs_client_accounts
ColumnTypeDescription
account_idPKINTEGERUnique client account identifier
account_nameVARCHAR(100)Client account name
regionVARCHAR(50)Client sales region
tcs_sales_transactions
ColumnTypeDescription
transaction_idPKINTEGERUnique sales transaction identifier
account_idINTEGERReferences tcs_client_accounts.account_id
sale_dateDATEDate of the sale
amountNUMERIC(12,2)Sales amount in USD
Tablestcs_client_accountstcs_sales_transactions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results