Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Performers by Department Query

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

Your question is Top Performers by Department 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

Unum's Data Science team wants a department-level view of its strongest active employees. Write a PostgreSQL query that combines employee, review, and performance outcome data to rank performers within each department.

Requirements

  1. Include only active employees assigned to a department and having at least one non-null review score.
  2. Calculate each employee's average review score and average performance outcome score.
  3. Calculate a performance score using 70% of the average review score and 30% of the average outcome score. Treat missing outcome scores as zero.
  4. Rank employees independently within each department and return the top three, using employee ID as a deterministic tie-breaker.
  5. Return department name, employee name, both averages, the calculated performance score, and the employee's rank.

Schema

departments
ColumnTypeDescription
department_idPKINTEGERUnique department identifier
department_nameVARCHAR(100)Department name
employees
ColumnTypeDescription
employee_idPKINTEGERUnique employee identifier
employee_nameVARCHAR(100)Employee's full name
department_idINTEGERAssigned department identifier
employment_statusVARCHAR(20)Current employment status
performance_reviews
ColumnTypeDescription
review_idPKINTEGERUnique review identifier
employee_idINTEGEREmployee being reviewed
review_periodVARCHAR(20)Review period label
review_scoreNUMERIC(5,2)Review score
performance_results
ColumnTypeDescription
result_idPKINTEGERUnique outcome record identifier
employee_idINTEGEREmployee associated with the outcome
performance_periodVARCHAR(20)Outcome period label
outcome_scoreNUMERIC(5,2)Measured performance outcome score
Tablesdepartmentsemployeesperformance_reviewsperformance_results
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results