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
SQL for Cost Variances and Labor Hours
00:00
5 left

SQL for Cost Variances and Labor Hours

MediumSQL · PostgreSQL

Problem

Burns & McDonnell project controls needs a subcontractor-level view of financial and labor performance across large projects. Write a PostgreSQL query that summarizes eligible project cost records.

Requirements

  1. Use a CTE to identify projects with a contract value greater than $1,000,000. Exclude projects at exactly $1,000,000 and projects with a NULL contract value.
  2. Join the eligible projects to project_costs and subcontractors.
  3. Group results by subcontractor ID and name.
  4. Return total cost variance, calculated as actual cost minus budgeted cost, and total labor hours. Treat NULL cost or labor values as zero, and order by subcontractor ID ascending.

Schema

projects
ColumnTypeDescription
project_idPKINTUnique project identifier
project_nameVARCHAR(100)Project name
contract_valueDECIMAL(14,2)Approved project contract value
statusVARCHAR(20)Current project status
project_costs
ColumnTypeDescription
cost_idPKINTUnique cost record identifier
project_idINTReferences projects.project_id
subcontractor_idINTReferences subcontractors.subcontractor_id
budgeted_costDECIMAL(12,2)Budgeted amount for the cost record
actual_costDECIMAL(12,2)Actual incurred amount
labor_hoursDECIMAL(10,2)Reported labor hours
subcontractors
ColumnTypeDescription
subcontractor_idPKINTUnique subcontractor identifier
subcontractor_nameVARCHAR(100)Subcontractor legal or display name
Tablesprojectsproject_costssubcontractors
Interviewer

Your question is SQL for Cost Variances and Labor Hours. 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.