Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL for Underperforming Shifts

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

Your question is SQL for Underperforming Shifts. 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

How would you write a query to identify the top 10% of underperforming shifts in a given month?

Use the shifts and shift_targets tables. For this exercise, underperformance is measured by the lowest actual-to-target percentage. Include only shifts in February 2025 with non-null actual units and positive targets.

Output

  1. One row per selected shift with the columns shift_id, store_id, shift_date, shift_name, actual_units, target_units, and performance_pct
  2. Include the lowest 10% of eligible shifts, rounding the required count up
  3. Order by underperformance, then shift date and shift ID for ties

Schema

shifts
ColumnTypeDescription
shift_idPKINTUnique shift identifier
store_idINTStore associated with the shift
shift_dateDATECalendar date of the shift
shift_nameVARCHAR(30)Shift label
actual_unitsINTUnits processed during the shift
shift_targets
ColumnTypeDescription
target_idPKINTUnique target record identifier
shift_idINTReferenced shift identifier
target_unitsINTTarget units for the shift
Tablesshiftsshift_targets
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results