Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Joins for Calibration Logs

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

Your question is SQL Joins for Calibration Logs. 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

Hexagon Ab needs a staffing view for active products such as HxDR and HxGN EAM. Write a PostgreSQL query that lists every active project, assigned employees, and each employee's manager.

Requirements

  1. Use a RIGHT OUTER JOIN so active projects remain in the result even when they have no staffing assignment.
  2. Use LEFT OUTER JOIN to retain assignments whose employee is currently unknown.
  3. Use a self-join on employees to resolve each employee's manager.
  4. Return project code, project name, employee name, manager name, and allocation percentage, ordered by project code and employee name, with unassigned rows last.

Schema

employees
ColumnTypeDescription
employee_idPKINTEmployee identifier
employee_nameVARCHAR(100)Employee's full name
manager_idINTEmployee ID of the manager
departmentVARCHAR(80)Employee department
employee_projects
ColumnTypeDescription
assignment_idPKINTAssignment identifier
employee_idINTAssigned employee
project_idINTAssigned project
allocation_pctINTPercentage of working time allocated
projects
ColumnTypeDescription
project_idPKINTProject identifier
project_codeVARCHAR(30)Project or product code
project_nameVARCHAR(150)Project or product name
statusVARCHAR(20)Project lifecycle status
Tablesemployeesemployee_projectsprojects
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results