Report the average
experience years of all the employees for each project, rounded to 2 digits.
Return the result table in any order.
Hints
Hint#1
When we have more than one tables we must think about joins first
Hint#2
SQL has a function AVG(column_name)
returns the average value of that column
Hint#3
Here we are asked to find the average for each project, we must think about Grouping
Explanation
We want to find the average experience years for each project, so we must join the two tables on the employee_id
column, then we must group the result by the project_id
column, and finally we must find the average of the experience_years
column.
When selecting the average of a column we must use the AVG(column_name)
function, and to round the result to 2 digits we must use the ROUND()
function, then we use AS
to give the column an alias (average_years
)
SQL Solution
select p.project_id, round(avg(e.experience_years),2) as average_years
from Project p
inner join Employee e on e.employee_id = p.employee_id
group by p.project_id;