Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Track Agency Utilization Query

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

Your question is Track Agency Utilization Query. Start with the requirements and the four 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

Omnicom Health operations leaders need a weekly view of team utilization across agency staff. Write a PostgreSQL query using the capacity and time-entry data below.

Requirements

  1. Return one row per team and capacity week from January 6 through January 19, 2025.
  2. Calculate total logged hours and total available hours for each team and week. Include weeks with capacity but no time entries.
  3. Calculate utilization_rate as logged hours divided by available hours, expressed as a percentage rounded to two decimals. Return 0.00 when the available-hours total is zero.
  4. Order results by team name and week start.

Schema

teams
ColumnTypeDescription
team_idPKINTPrimary key for an agency team
team_nameVARCHAR(100)Agency team name
employees
ColumnTypeDescription
employee_idPKINTPrimary key for an employee
employee_nameVARCHAR(100)Employee's name
team_idINTTeam assigned to the employee
roleVARCHAR(80)Employee's agency role
weekly_capacity
ColumnTypeDescription
employee_idPKINTEmployee with planned weekly capacity
week_startPKDATEMonday starting the capacity week
available_hoursNUMERIC(6,2)Hours available to be scheduled
time_entries
ColumnTypeDescription
entry_idPKINTPrimary key for a time entry
employee_idINTEmployee who logged the hours
entry_dateDATEDate the work was logged
hoursNUMERIC(6,2)Hours logged, possibly missing
Tablesteamsemployeesweekly_capacitytime_entries
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results