Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Running Total Over 7 Days

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

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

Accenture SynOps uses an operations dashboard to monitor daily transaction revenue. Write a PostgreSQL query that calculates the revenue for each calendar date and the rolling revenue total for that date and the six preceding calendar days.

Requirements

  1. Aggregate transaction amounts by calendar date.
  2. Include dates with no transactions, showing daily revenue as 0.
  3. Calculate a seven-calendar-day rolling total using a window function.
  4. Return results in chronological order for all dates in reporting_calendar.

A transaction with a NULL amount contributes no revenue. Transactions without a valid calendar date are outside the reporting calendar and should not appear in the result.

Schema

reporting_calendar
ColumnTypeDescription
calendar_datePKDATECalendar date included in reporting
synops_transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
transaction_dateDATEDate on which the transaction occurred
amountNUMERIC(10,2)Transaction revenue
channelVARCHAR(30)Source channel for the transaction
Tablesreporting_calendarsynops_transactions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results