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
Consecutive Shifts Over 12 Hours
00:00
5 left

Consecutive Shifts Over 12 Hours

MediumSQL · PostgreSQL

Problem

Write a query to identify employees who have worked consecutive shifts exceeding twelve hours.

Treat two shifts as consecutive when the later shift starts no more than 30 minutes after the earlier shift ends. Return each qualifying pair once, excluding incomplete shifts. Sort the results by employee ID and the first shift's start time.

Output

  1. One row per qualifying consecutive shift pair
  2. Columns: employee_id, employee_name, first_shift_id, first_shift_start, first_shift_end, next_shift_start, next_shift_end, and consecutive_hours
  3. Include only pairs spanning more than 12 hours from the first shift start to the next shift end
  4. Order by employee_id, then first_shift_start

Schema

employees
ColumnTypeDescription
employee_idPKINTUnique employee identifier
employee_nameVARCHAR(100)Employee's full name
departmentVARCHAR(80)Employee's department
shifts
ColumnTypeDescription
shift_idPKINTUnique shift identifier
employee_idINTEmployee assigned to the shift
shift_startTIMESTAMPShift start timestamp
shift_endTIMESTAMPShift end timestamp
Tablesemployeesshifts
Interviewer

Your question is Consecutive Shifts Over 12 Hours. 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.