Study - Problems(IT)/LeetCode - SQL

1075. Project Employees I

Dev.D 2024. 11. 10. 04:59

* Problem

Write an SQL query that reports the average experience years of all the employees for each project, rounded to 2 digits.

Return the result table in any orde

Explanation: The average experience years for the first project is 
(3 + 2 + 1) / 3 = 2.00 and for the second project is (3 + 2) / 2 = 2.50

 

* Solution 

# Write your MySQL query statement below
select  a.project_id project_id,
            round(avg(b.experience_years),2) average_years
   from Project a
   left join Employee b
      on a.employee_id = b.employee_id
    group by a.project_id