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
Weekly Sales and Margin SQL
00:00
5 left

Weekly Sales and Margin SQL

MediumSQL · PostgreSQL

Problem

Write a SQL query to calculate weekly sales, labor cost, and margin by McDonald's store using window functions or CTEs.

Use the provided McDonald's store, sales, and labor data. Treat weeks as Monday through Sunday and include every store-week with sales or labor activity. Missing sales or labor amounts should be treated as zero.

Output

  1. One row per store and week, excluding weeks with no activity
  2. Columns: store_id, store_name, week_start, weekly_sales, labor_cost, margin, prior_week_margin, and margin_change
  3. Margin equals weekly sales minus labor cost; week-over-week fields compare rows within each store
  4. Order by store_id, then week_start ascending

Schema

stores
ColumnTypeDescription
store_idPKINTUnique McDonald's store identifier
store_nameVARCHAR(100)Store display name
regionVARCHAR(50)Operating region
store_sales
ColumnTypeDescription
sale_idPKINTUnique sales record identifier
store_idINTReferenced McDonald's store
sale_dateDATEDate of the sales record
sales_amountNUMERIC(12,2)Sales amount for the record
store_labor
ColumnTypeDescription
labor_idPKINTUnique labor record identifier
store_idINTReferenced McDonald's store
labor_dateDATEDate of the labor record
labor_costNUMERIC(12,2)Labor cost for the record
Tablesstoresstore_salesstore_labor
Interviewer

Your question is Weekly Sales and Margin SQL. Start with the requirements and the three 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.