Database/Practice

[Database/Practice]02. Oracle hr account table(2)

양승길 2016. 6. 8. 21:51

02. Oracle hr account table(2)

5. 부서별로 가장 적은 급여를 받고 있는 직원의 이름, 부서이름, 급여를 출력하시오. 이름은 last_name만 출력하며, 부서이름으로 오름차순 정렬하고, 부서가 같을 경우 이름을 기준으로 오름차순 정렬하세요.

1
2
3
4
5
6
7
8
select   e1.last_name 사원이름, d1.department_name 부서이름, j1.급여 급여
from     employees e1, departments d1, (select   department_id 부서아이디, min(salary) 급여 
                                        from     employees 
                                        group by department_id) j1
where    d1.department_id = e1.department_id and 
         j1.부서아이디 = e1.department_id and 
         j1.급여 = e1.salary
order by d1.department_name, e1.last_name
cs



6. 각 도시(City)에 있는 모든 부서 직원들의 평균급여를 조회하고자 한다. 평균급여가 가장 낮은 도시부터 도시명(City)과 평균연봉, 해당 도시의 직원 수를 출력하시오. 단, 도시에 근무하는 직원이 10명 이상인 곳은 제외하고 조회한다.

1
2
3
4
5
6
select   l1.city 도시이름, round(avg(e1.salary),0) 평균급여, count(*) 직원수
from     locations l1, employees e1, departments d1
where    e1.department_id = d1.department_id and d1.location_id=l1.location_id
group by l1.city
having   count(*)< 10
order by round(avg(e1.salary),0)
cs

7. 30번 부서에 근무하는 사원들의 직책(job_title)별 평균 급여가 2000 이상인 직책(job_title)과 그 직책의 평균 급여.

1
2
3
4
5
select   j1.job_title 직책, to_char(avg(e1.salary),'999,999') 평균급여
from     employees e1, jobs j1
where    e1.job_id = j1.job_id and e1.department_id=30
group by j1.job_title
having   avg(e1.salary)>2000
cs


8. 'Public Account' 의 직책(job_title)으로 과거에 근무한 적이 있는 모든 사원의 사번과 이름을 출력하세요. (현재 'Public  Account'의 직책(job_title)으로 근무하는 사원은 고려하지 않습니다.)

1
2
3
select e1.employee_id 사번, e1.first_name || ' ' || e1.last_name 이름
from   employees e1, jobs j1, job_history jh1
where  e1.employee_id = jh1.employee_id and jh1.job_id = j1.job_id and j1.job_title='Public Accountant'
cs


'Database > Practice' 카테고리의 다른 글

[Database/Practice]01. Oracle hr account table(1)  (0) 2016.06.08