Database/Practice

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

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

01. Oracle hr account table(1)


1. 자신이 속한 부서의 평균 연봉보다 많은 연봉을 받은 사원의 아이디, 부서아이디, 연봉, 부서평균연봉을 조회하라.

(부서평균연봉은 반올림하여 정수로 출력할 것.  부서평균연봉이 많은 사람부터 출력할 것.)

1
2
3
4
5
6
select    e.employee_id 사번, e.department_id 부서번호, e.salary 연봉, em.부서평균연봉 부서평균연봉 
from      employees e, (select   department_id 부서번호, round(avg(salary),0) 부서평균연봉 
                        from     employees 
                        group by department_id) em
where     em.부서번호=e.department_id and e.salary > em.부서평균연봉
order by  em.부서평균연봉 desc
cs


2. employees 테이블에서 급여를 많이 받는 순서대로 조회했을 때 6번째부터 10번째까지 5명의 last_name, first_name, salary를 조회하는 SQL문장을 작성하시오.

1
2
3
4
select e.ranking ranking, e.last_name last_name, e.first_name first_name, e.salary salary
from   (select rank() over(order by salary desc) ranking, last_name, first_name, salary 
       from   employees) e
where  ranking between 6 and 10
cs


3. 직책(Job Title)이 Sales Manager인 사원들의 입사 년도와 입사 년도(hire_date)별 평균 급여를 출력하시오. 출력시 기준으로 오름차순 정렬하세요.

1
2
3
4
5
select   to_char(e.hire_date, 'yyyy') 년도, to_char(avg(e.salary),'999,999') 급여 
from     employees e, jobs j
where    e.job_id=j.job_id and job_title='Sales Manager' 
group by to_char(hire_date, 'yyyy')
order by to_char(hire_date, 'yyyy')
cs


4. 사원의 부서가 속한 도시(City)가 'Seattle'인 사원의 이름, 해당 사원의 매니저이름, 사원의 부서이름을 출력하세요. 이때 사원의 매니저가 없을 경우 '<없음>'이라고 출력하여 주세요. 이름은 last_name만 출력하며, 사원의 이름으로 오름차순 정렬하세요.

1
2
3
4
5
6
7
select   e1.last_name 사원이름, nvl(e2.last_name,'<없음>') 매니저이름, d1.department_name 부서이름
from     employees e1, employees e2, departments d1, locations l1
where    e1.department_id = d1.department_id and 
         d1.location_id = l1.location_id and 
         e1.manager_id = e2.employee_id(+) and
         l1.city='Seattle'
order by e1.last_name 
cs


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

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