Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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 feedbackSuccess 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 Rolling 4-Week Regional Performance
00:00
5 left

SQL Rolling 4-Week Regional Performance

HardSQL · PostgreSQL

Problem

Write a SQL query to analyze weekly operational performance by region at Medzed, joining orders and staffing tables and calculating a rolling 4-week average. Include completed orders and staffing hours for every region-week represented in either table. Treat weeks as starting on Monday and avoid division by zero.

Output

  1. One row per region and week, with region, week_start, completed_orders, staffed_hours, orders_per_staff_hour, and rolling_4_week_avg.
  2. Include unmatched region-weeks, showing zero counts or hours where appropriate and NULL performance when staffing hours are zero.
  3. Sort by region, then week_start ascending.

Schema

orders
ColumnTypeDescription
order_idPKINTUnique order identifier
regionVARCHAR(50)Medzed operating region
order_dateDATEDate the order was created
statusVARCHAR(20)Order lifecycle status
staffing
ColumnTypeDescription
staffing_idPKINTUnique staffing record identifier
regionVARCHAR(50)Medzed operating region
staffing_dateDATEDate staffing was recorded
staffed_hoursDECIMAL(10,2)Available staff hours
Tablesordersstaffing
Interviewer

Your question is SQL Rolling 4-Week Regional Performance. 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.