Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL 7-Day Running Total by Store

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

Your question is SQL 7-Day Running Total by Store. 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

Business Context

Arby's Marketing Analytics uses store-level sales trends to evaluate campaign performance and promotional lift. A seven-day rolling total helps smooth daily variation while preserving store-level detail.

Task

Write a PostgreSQL query that returns each store's daily sales and its seven-day running sales total. Include dates with recorded sales, aggregate multiple transactions from the same store and date before applying the rolling calculation, and exclude transactions that do not match a known store.

Requirements

  1. Join sales_transactions to stores to return the store name.
  2. Calculate daily sales per store using SUM(sale_amount).
  3. Calculate a calendar-based seven-day total that includes the current date and the six preceding calendar days.
  4. Return results ordered by store ID and sales date.

Schema

stores
ColumnTypeDescription
store_idPKINTEGERUnique Arby's restaurant identifier
store_nameVARCHAR(100)Restaurant name
cityVARCHAR(80)Restaurant city
regionVARCHAR(40)Operating region
sales_transactions
ColumnTypeDescription
transaction_idPKINTEGERUnique transaction identifier
store_idINTEGERReferenced restaurant identifier
sale_dateDATEDate of the sale
sale_amountNUMERIC(10,2)Transaction sales amount
channelVARCHAR(20)Sales channel
Tablesstoressales_transactions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results