Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL for Cost Variances and Labor Hours

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

Your question is SQL for Cost Variances and Labor Hours. Start with the requirements and the three 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

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
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results