Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Week-Over-Week Store Sales
00:00
5 left

Week-Over-Week Store Sales

MediumSQL · PostgreSQL

Problem

Write a SQL query to calculate week-over-week sales change for each 7-Eleven store using a date table and sales table.

Use the calendar weeks represented in the date table and include weeks with no sales as zero. Return the first available week for each store with NULL comparison values.

Output

  1. One row per store and calendar week, including zero-sales weeks.
  2. Columns: store_id, week_start, weekly_sales, prior_week_sales, wow_change, and wow_change_pct.
  3. wow_change_pct should be NULL when prior-week sales are NULL or zero. Order by store_id, then week_start.

Schema

date_dim
ColumnTypeDescription
calendar_datePKDATECalendar date
week_startDATEStart date of the reporting week
sales
ColumnTypeDescription
sale_idPKINTUnique sale identifier
store_idVARCHAR(10)7-Eleven store identifier
sale_dateDATEDate on which the sale occurred
sales_amountNUMERIC(10,2)Sales amount for the transaction
Tablesdate_dimsales
Interviewer

Your question is Week-Over-Week Store Sales. Start with the requirements and the two tables in the Question tab.

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.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.