You are given two tables: Project and Employee.
The Project table contains information about which employees are working on each project, where (project_id, employee_id) is the primary key.
The Employee table contains information about each employee, including their experience_years.
Write an SQL query that reports the average experience years of all employees for each project, rounded to 2 decimal places.
Return the result table in any order.
Table Schema
| Column Name | Type | Description |
|---|---|---|
project_id
PK
|
int | Project identifier |
employee_id
PK
|
int | Employee identifier, foreign key to Employee table |
| Column Name | Type | Description |
|---|---|---|
employee_id
PK
|
int | Employee identifier, primary key |
name
|
varchar | Employee name |
experience_years
|
int | Years of experience (guaranteed not NULL) |
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 | average_years |
|---|---|
| 1 | 2 |
| 2 | 2.5 |
For project 1: employees 1, 2, 3 have experience years (3, 2, 1), so average = (3+2+1)/3 = 2.00. For project 2: employees 1, 4 have experience years (3, 2), so average = (3+2)/2 = 2.50.
| project_id | employee_id |
|---|---|
| 1 | 1 |
| 2 | 2 |
| employee_id | name | experience_years |
|---|---|---|
| 1 | Alice | 5 |
| 2 | Bob | 8 |
| project_id | average_years |
|---|---|
| 1 | 5 |
| 2 | 8 |
Each project has only one employee, so the average equals the individual employee's experience years.
Constraints
-
1 ≤ project_id ≤ 100 -
1 ≤ employee_id ≤ 1000 -
0 ≤ experience_years ≤ 50 -
experience_yearsis guaranteed to be not NULL