Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
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
Sign up free to run your codeLog inLn 1
Run your query to see results here.