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
SQL Variance vs Target
00:00
5 left

SQL Variance vs Target

MediumSQL · PostgreSQL

Problem

Write a SQL query to compare store-level sales, labor cost, and food waste by week and identify the stores with the largest variance from target.

Assume a store should be evaluated only when actual metrics and positive targets exist for the same week. Define overall variance as the average of the absolute percentage variances across sales, labor cost, and food waste.

Output

  1. Return one row per highest-variance store and week, including ties.
  2. Include week_start, store_id, store_name, the three percentage variances, overall_variance_pct, and variance_rank.
  3. Sort by week_start, then overall_variance_pct descending, then store_id.

Schema

stores
ColumnTypeDescription
store_idPKINTUnique McDonald's store identifier
store_nameVARCHAR(100)Store display name
cityVARCHAR(80)Store city
regionVARCHAR(50)Operating region
weekly_store_metrics
ColumnTypeDescription
metric_idPKINTUnique weekly metrics record
store_idINTReferenced store
week_startDATEMonday starting the reporting week
salesDECIMAL(12,2)Weekly sales amount
labor_costDECIMAL(12,2)Weekly labor cost
food_wasteDECIMAL(12,2)Weekly food waste amount
weekly_store_targets
ColumnTypeDescription
target_idPKINTUnique weekly target record
store_idINTReferenced store
week_startDATEMonday starting the target week
sales_targetDECIMAL(12,2)Target weekly sales
labor_cost_targetDECIMAL(12,2)Target weekly labor cost
food_waste_targetDECIMAL(12,2)Target weekly food waste
Tablesstoresweekly_store_metricsweekly_store_targets
Interviewer

Your question is SQL Variance vs Target. 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.