본문 바로가기

SQL

SQL 연습문제

728x90
SMALL

1. 연봉이 120,000 이상되는 사원들의 이름 및 연봉을 출력하시오

SQL> select last_name, salary*12
  2  from employees
  3  where salary*12>=120000;

2. 사원번호가 176인 사원의 이름과 부서 번호를 출력하시오.

SQL> select last_name, department_id
  2  from employees
  3  where employee_id=176;

3. 연봉이 150,000 에서 200,000의 범위 이외인 사원들의 이름 및 연봉을 출력하시오. 단 연봉은 AnnSal로 출력하시오

SQL> 1  select last_name, salary*12 "AnnSal"
  2  from employees
  3  where salary*12 not between 150000 and 200000;

4. 2003/01/01 일부터 2005/05/30 일 사이에 고용된 사원들의 이름, 사번, 고용일자를 출력하시오. 고용일자를 역순으로 정렬하시오.

SQL>  1  select last_name, employee_id, hire_date
  2  from employees
  3  where hire_date between '03/01/01' and '05/05/30'
  4* order by hire_date desc

5. 20번 및 50번 부서에서 근무하는 모든 사원들의 이름 및 부서 번호를 알파벳순으로 출력하시오

SQL> 1  select last_name, department_id
  2  from employees
  3  where department_id in (20,50)
  4* order by department_id asc;
  
  //asc는 기본값 오름차순이므로 생략 가능

6. 20번 및 50번 부서에 근무하며, 연봉이 200,000 ~ 250000 사이인 사원들의 이름 및 연봉을 출력하시오

SQL> 1  select last_name, salary*12
  2  from employees
  3  where department_id in (20,50)
  4* and salary*12 between 200000 and 250000

7. 2006년도에 고용된 모든 사람들의 이름 및 고용일을 조회한다

SQL>1  select last_name, hire_date
  2  from employees
  3* where hire_date like '06%'

8. 매니저가 없는 사람들의 이름 및 업무를 출력하시오.

SQL> select last_name, job_id
  2  from employees
  3  where manager_id is null;

9. 매니저가 있는 사람들의 이름 및 업무, 매니저번호를 조회한다.

SQL> select last_name, job_id, manager_id
  2  from employees
  3  where manager_id is not null;

10. 커미션을 받는 모든 사원들의 이름, 연봉 및 커미션을 출력하시오.

      - 연봉을 역순으로 정렬하고, 연봉은 ANNSAL로 출력하시오

SQL> select last_name, salary*12 as ANNSAL, commission_pct
from employees
where commission_pct is not null
order by ANNSAL desc;

11. 이름의 네번째 글자가 a인 사원의 이름을 조회하시오

SQL> 1  select last_name
  2  from employees
  3* where last_name like '___a%'

12. 이름에 a 및 e 글자가 있는 사원의 이름을 조회하시오

SQL> select last_name
  2  from employees
  3  where last_name like '%a%' and last_name like '%e%';

13. 급여가 2500,3500,7000이 아니며 직업이 SA_REP나 ST_CLERK인 사원의 이름과, 급여, 직업을 출력하시오

SQL>1  select last_name, salary, job_id
  2  from employees
  3  where  salary not in(2500,3500,7000)
  4* and job_id in ('SA_REP', 'ST_CLERK')

14. 30번 부서내의 모든 직업들을 유일한 값으로 출력하시오. 90번 부서 또한 포함하고, 직업을 오름차순으로 출력하시오.

SQL> 1  select distinct job_id, department_id
//distibct->중복재거
  2  from employees
  3  where department_id in(30,90)
  4* order by job_id

15. 모든 사원들의 이름, 부서 이름 및 부서 번호를 출력하시오

SQL> 1  select e.employee_id, e.last_name, d.department_name,d.department_id
  2  from employees e, departments d
  3* where e.department_id = d.department_id

16.급여가 15000 이상인 사원의 이름과 급여, 그 사원이 근무하는 부서이름을 출력하시오.

SQL> 1  select e.last_name, e.salary, d.department_name
  2  from employees e, departments d
  3 where e.department_id = d.department_id
  4* and e.salary>=15000

17. 연봉이 150000 이상인 사원의 이름과 연봉, 그 사원이 근무하는 부서이름과 부서가 위치한 지역번호를 출력하시오. 단 연봉은 AnnSal로 출력하시오.

SQL>1  select e.last_name, e.salary*12 "AnnSal", d.department_name, d.location_id
  2  from employees e, departments d
  3  where e. department_id = d.department_id
  4* and salary*12>=150000

19. 회사에 근무하는 사원중 급여 등급이 4인 사원의 이름과 급여와 사원별 급여등급을 내림차순으로 정렬하여 출력하시오.

select e.last_name, e.salary, j.grade
from employees e. salgrade j
where e.salary Between j.losal And j.hisal
and j.grade =4
order by e.salary desc;

20. 커미션을 받는 모든 사람들의 이름, 부서 명, 지역 ID 및 도시명을 출력하시오

SQL> 1  select e.last_name, d.department_name, l.location_id, l.city
  2  from employees e, departments d, locations l
  3  where e.department_id = d.department_id
  4  and d.location_id = l.location_id
  5* and e.commission_pct is not null
728x90
LIST