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 for Rolling Productivity Targets
00:00
5 left

SQL for Rolling Productivity Targets

HardSQL · PostgreSQL

Problem

Amazon Services operations leaders need to identify recurring shift patterns whose productivity remains below target. Write a PostgreSQL query that evaluates each shift date against a rolling 30-day window.

Requirements

  1. Join shift assignments, productivity records, and shift targets.
  2. Calculate productivity as total completed units divided by total labor hours for each site, shift code, and date.
  3. For each shift date, calculate the rolling 30-day average productivity, observation count, and count of below-target observations.
  4. Return only shift dates with at least three observations in the window where every observation is below target. Round productivity and rolling averages to two decimal places.

Schema

shifts
ColumnTypeDescription
shift_idPKINTShift assignment identifier
site_idINTAmazon Services site identifier
shift_codeVARCHAR(20)Shift classification
shift_dateDATEDate on which the shift operated
shift_productivity
ColumnTypeDescription
productivity_idPKINTProductivity record identifier
shift_idINTRelated shift assignment
units_completedINTUnits completed during the record interval
labor_hoursNUMERIC(8,2)Labor hours recorded for the interval
productivity_targets
ColumnTypeDescription
site_idPKINTAmazon Services site identifier
shift_codePKVARCHAR(20)Shift classification
target_units_per_hourNUMERIC(8,2)Required units per labor hour
Tablesshiftsshift_productivityproductivity_targets
Interviewer

Your question is SQL for Rolling Productivity Targets. 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.