You are given two tables: Project and Employee.
The Project table shows which employees are working on which projects, while the Employee table contains information about each employee including their experience years.
Write a SQL query to find the most experienced employees in each project. If there are multiple employees with the same maximum experience years in a project, include all of them in the result.
Return the result in any order.
Table Schema
| Column Name | Type | Description |
|---|---|---|
project_id
PK
|
int | Project identifier |
employee_id
PK
|
int | Employee identifier working on the project |
| Column Name | Type | Description |
|---|---|---|
employee_id
PK
|
int | Unique employee identifier |
name
|
varchar | Employee name |
experience_years
|
int | Years of experience |
Input & Output
| project_id | employee_id |
|---|---|
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| 2 | 1 |
| 2 | 4 |
| employee_id | name | experience_years |
|---|---|---|
| 1 | Khaled | 3 |
| 2 | Ali | 2 |
| 3 | John | 1 |
| 4 | Doe | 2 |
| project_id | employee_id | name | experience_years |
|---|---|---|---|
| 1 | 1 | Khaled | 3 |
| 2 | 1 | Khaled | 3 |
In project 1, Khaled has 3 years of experience, Ali has 2, and John has 1. Khaled is the most experienced. In project 2, Khaled (3 years) and Doe (2 years) are working, so Khaled is again the most experienced.
| project_id | employee_id |
|---|---|
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| employee_id | name | experience_years |
|---|---|---|
| 1 | Alice | 5 |
| 2 | Bob | 5 |
| 3 | Charlie | 3 |
| project_id | employee_id | name | experience_years |
|---|---|---|---|
| 1 | 1 | Alice | 5 |
| 1 | 2 | Bob | 5 |
In project 1, both Alice and Bob have 5 years of experience, which is the maximum. Since there's a tie, both employees are included in the result.
| project_id | employee_id |
|---|---|
| 1 | 1 |
| 2 | 2 |
| employee_id | name | experience_years |
|---|---|---|
| 1 | David | 2 |
| 2 | Eve | 4 |
| project_id | employee_id | name | experience_years |
|---|---|---|---|
| 1 | 1 | David | 2 |
| 2 | 2 | Eve | 4 |
Each project has only one employee, so each employee is automatically the most experienced in their respective project.
Constraints
-
1 ≤ project_id ≤ 100 -
1 ≤ employee_id ≤ 10000 -
1 ≤ name.length ≤ 20 -
1 ≤ experience_years ≤ 50