Project Employees III - Problem
Project Employees III - Finding the Most Experienced Team Members
You are a project manager at a tech company, and you need to identify the most experienced employees working on each project. This is crucial for making important technical decisions and assigning leadership roles.
Problem: Given two database tables -
Key Details:
• If multiple employees have the same maximum experience years in a project, return all of them
• The result should show
• Return results in any order
This problem tests your ability to work with window functions, joins, and ranking in SQL - essential skills for database management and analytics roles.
You are a project manager at a tech company, and you need to identify the most experienced employees working on each project. This is crucial for making important technical decisions and assigning leadership roles.
Problem: Given two database tables -
Project (which maps employees to projects) and Employee (which contains employee details including experience), write a SQL query to find the most experienced employee(s) in each project.Key Details:
• If multiple employees have the same maximum experience years in a project, return all of them
• The result should show
project_id, employee_id, name, and experience_years• Return results in any order
This problem tests your ability to work with window functions, joins, and ranking in SQL - essential skills for database management and analytics roles.
Input & Output
example_1.sql — Basic Case
$
Input:
Project table:
| project_id | employee_id |
|------------|-------------|
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| 2 | 1 |
| 2 | 4 |
Employee table:
| employee_id | name | experience_years |
|-------------|-------|------------------|
| 1 | Alice | 12 |
| 2 | Bob | 7 |
| 3 | Carol | 10 |
| 4 | Dave | 12 |
›
Output:
| project_id | employee_id | name | experience_years |
|------------|-------------|-------|------------------|
| 1 | 1 | Alice | 12 |
| 2 | 1 | Alice | 12 |
| 2 | 4 | Dave | 12 |
💡 Note:
In project 1, Alice has the maximum experience (12 years). In project 2, both Alice and Dave have maximum experience (12 years), so both are returned.
example_2.sql — Multiple Ties
$
Input:
Project table:
| project_id | employee_id |
|------------|-------------|
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
Employee table:
| employee_id | name | experience_years |
|-------------|---------|------------------|
| 1 | Alice | 10 |
| 2 | Bob | 10 |
| 3 | Charlie | 10 |
›
Output:
| project_id | employee_id | name | experience_years |
|------------|-------------|---------|------------------|
| 1 | 1 | Alice | 10 |
| 1 | 2 | Bob | 10 |
| 1 | 3 | Charlie | 10 |
💡 Note:
All three employees have the same maximum experience (10 years) in project 1, so all are returned.
example_3.sql — Single Employee per Project
$
Input:
Project table:
| project_id | employee_id |
|------------|-------------|
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
Employee table:
| employee_id | name | experience_years |
|-------------|-------|------------------|
| 1 | Alice | 5 |
| 2 | Bob | 8 |
| 3 | Carol | 12 |
›
Output:
| project_id | employee_id | name | experience_years |
|------------|-------------|-------|------------------|
| 1 | 1 | Alice | 5 |
| 2 | 2 | Bob | 8 |
| 3 | 3 | Carol | 12 |
💡 Note:
Each project has only one employee, so each employee is automatically the most experienced in their respective project.
Constraints
- 1 ≤ project_id, employee_id ≤ 104
- employee_id in Project table exists in Employee table (foreign key constraint)
- 1 ≤ experience_years ≤ 50
- 1 ≤ name.length ≤ 20
- Each (project_id, employee_id) combination in Project table is unique
Visualization
Tap to expand
Understanding the Visualization
1
Gather Participants
Collect all hackathon-participant pairs with their skill levels
2
Group by Hackathon
Organize participants into their respective hackathons
3
Rank by Skill
Within each hackathon, rank participants by experience level
4
Select Leaders
Choose all rank-1 participants as team leaders (handles ties naturally)
Key Takeaway
🎯 Key Insight: Window functions with PARTITION BY allow us to rank employees within each project independently, making it easy to handle ties and find all most experienced employees in a single, efficient query.
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code