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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Get started
Operational Performance SQL Analysis
00:00
5 left

Operational Performance SQL Analysis

HardSQL · PostgreSQL

Problem

Write a SQL query to analyze operational performance by joining guest satisfaction, staffing, and occupancy data to identify the biggest drivers of service issues.

Use the three daily operational tables provided. Calculate service issue rates and compare staffing gaps with occupancy levels for operational days having complete, valid measurements.

Output

  1. One row per property and operational driver.
  2. Columns: property_id, driver_name, high_driver_issue_rate, low_driver_issue_rate, issue_rate_lift, and driver_rank.
  3. Include staffing-gap and occupancy-rate drivers, rank within each property by descending issue-rate lift, and break ties alphabetically by driver name.

Output details

  • Calculate issue rate as issue_count / survey_count * 100, staffing gap as scheduled_staff - actual_staff, and occupancy rate as rooms_occupied / rooms_available * 100.
  • Exclude records where survey_count <= 0, actual_staff is NULL, or rooms_available <= 0; also exclude NULL issue rates and driver values.
  • Round high and low issue rates and issue-rate lift to 2 decimal places.
  • Assign ascending driver values to four equal-count quartiles, using quartile 4 as high and quartile 1 as low.
  • Use the difference between high and low average issue rates as the lift, and rank with dense ranking, placing NULL lifts last.
  • Order the final rows by property_id ascending, then driver_rank ascending, then driver_name alphabetically.

Schema

guest_satisfaction_daily
ColumnTypeDescription
satisfaction_idPKINTDaily satisfaction record identifier
property_idVARCHAR(20)Property identifier
service_dateDATEOperational date
survey_countINTNumber of guest surveys received
issue_countINTSurveys reporting a service issue
staffing_daily
ColumnTypeDescription
staffing_idPKINTDaily staffing record identifier
property_idVARCHAR(20)Property identifier
service_dateDATEOperational date
scheduled_staffINTNumber of staff scheduled
actual_staffINTNumber of staff who worked
occupancy_daily
ColumnTypeDescription
occupancy_idPKINTDaily occupancy record identifier
property_idVARCHAR(20)Property identifier
service_dateDATEOperational date
rooms_availableINTRooms available for occupancy
rooms_occupiedINTRooms occupied
Tablesguest_satisfaction_dailystaffing_dailyoccupancy_daily
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the three tables are in the Question tab.

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.