3. 지역별로 소속되어 있는 사원 수의 합
STUDY/ORACLE_SQL_2일차 2007. 6. 22. 13:43지역별로 소속되어 있는 사원 수의 합을 나타내자.
결과
지역 사원 수
Europe
Americas
Asia
Middle East and Africa
SELECT region_name, COUNT(employee_id)
FROM employees e JOIN departments d
ON e.department_id = d.department_id
JOIN locations l
ON l.location_id = d.location_id
JOIN countries c
ON c.country_id = l.country_id
JOIN regions r
ON r.region_id = c.region_id
GROUP BY region_name;
SELECT region_name, COUNT(employee_id)
FROM employees e JOIN departments d
ON e.department_id = d.department_id
JOIN locations l
ON l.location_id = d.location_id
JOIN countries c
ON c.country_id = l.country_id
RIGHT OUTER JOIN regions r
ON r.region_id = c.region_id
GROUP BY region_name;