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
Rolling Desk Utilization With SQL
00:00
5 left

Rolling Desk Utilization With SQL

MediumSQL · PostgreSQL

Problem

Write a query using SQL window functions to calculate the rolling three-month average of desk utilization.

Calculate utilization as desks used divided by desks available, expressed as a percentage. Treat a zero capacity as undefined and allow missing utilization values to be ignored by the average.

Output

  1. One row per matched location and month.
  2. Columns: location_name, month_start, utilization_rate, and rolling_three_month_avg.
  3. Include the current month and up to the prior two calendar months for each location.
  4. Order by location_name, then month_start.

Schema

locations
ColumnTypeDescription
location_idPKINTUnique identifier for a coworking location
location_nameVARCHAR(100)Name of the coworking location
desk_utilization
ColumnTypeDescription
utilization_idPKINTUnique monthly utilization record identifier
location_idINTLocation associated with the utilization record
month_startDATEFirst day of the utilization month
desks_availableINTNumber of desks available during the month
desks_usedINTNumber of desks used during the month
Tableslocationsdesk_utilization
Interviewer

Your question is Rolling Desk Utilization With SQL. 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.