Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Rolling 4-Week Regional Performance

HardSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is SQL Rolling 4-Week Regional Performance. Start with the requirements and the two tables on the right.

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.

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
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results