본문 바로가기

SQL/LeetCode

[SQL] Project Employees I(LeetCode/Oracle)

안녕하세요!

 

이번 포스팅은 LeetCode에 있는 Project Employees I 문제를 OracleDB로 풀어보려고 합니다!

 

(모든 문제는 Oracle로 풀이하겠습니다.)

 

1. 문제 링크 : https://leetcode.com/problems/project-employees-i/description/

 

2. 문제

Column name Type
project_id int
employee_id int
Column name Type
employee_id int
name varchar
experience_years int
[문제] Write an SQL query that reports the average experience years of all the employees for each project, rounded to 2 digits.

각 프로젝트에 대한 모든 직원의 평균 경력 연수를 2자리로 반올림해서 조회하는 문제입니다.

 

3. 제출 쿼리 및 설명

최종) PROJECT 테이블과 EMPLOYEE 테이블을 조인한 뒤, 프로젝트 별로 그룹화하고 직원의 경력 평균 연수를 계산합니다.

SELECT P.PROJECT_ID, ROUND(AVG(EXPERIENCE_YEARS), 2) AS AVERAGE_YEARS
FROM PROJECT P, EMPLOYEE E
WHERE P.EMPLOYEE_ID = E.EMPLOYEE_ID
GROUP BY P.PROJECT_ID
;