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
Week-over-Week Failure Rate Comparison
00:00
5 left

Week-over-Week Failure Rate Comparison

MediumSQL · PostgreSQL

Problem

Write a SQL query to compare current-week and previous-week failure rates by plant and machine type.

Use inspection_events, joined with plants and machine_types. Treat Monday as the first day of the week. A failure rate is failed inspections divided by all inspections in the relevant week. Include machine groups with activity in either week, and treat missing weekly activity as a 0% rate.

Output

  1. One row per plant and machine type.
  2. Columns: plant_name, machine_type, current_week_failure_rate, previous_week_failure_rate.
  3. Rates should be percentages rounded to two decimals, ordered by plant name and machine type.

Schema

inspection_events
ColumnTypeDescription
inspection_idPKINTUnique inspection identifier
plant_idINTPlant where the inspection occurred
machine_type_idINTMachine type inspected
inspected_atTIMESTAMPInspection timestamp
outcomeVARCHAR(20)Inspection result, such as Passed or Failed
plants
ColumnTypeDescription
plant_idPKINTUnique plant identifier
plant_nameVARCHAR(100)Plant name
regionVARCHAR(50)Geographic region
machine_types
ColumnTypeDescription
machine_type_idPKINTUnique machine type identifier
machine_type_nameVARCHAR(100)Machine type name
machine_familyVARCHAR(60)Broad machine classification
Tablesinspection_eventsplantsmachine_types
Interviewer

Your question is Week-over-Week Failure Rate Comparison. 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.