[Oracle][SQL] WHERE절과 연산자 연습 문제

Siyu·2024년 5월 27일
0

Oracle

목록 보기
8/8
post-thumbnail

앞에서 배운 WHERE절과 여러 연산자들의 활용을 통해 SQL연습 문제 풀어보기!!

연습문제😏

1. 사원 번호가 7788인 사원명, 부서번호 출력

select ename, dno from employee
where eno = 7788;

2. 급여가 2000을 넘는 사원의 이름, 급여를 출력

select ename, salary from employee
where salary > 2000;

3. 급여가 2000을 넘는 사원의 이름, 급여를 급여가 많은 순서로 출력

select ename, salary from employee
where salary > 2000 
Order by salary asc;

4. 모든 사람에 대해서 $300의 급여 인상을 적용한 후, 사원명, 인상전 급여, 인상 후 급여 출력 (별칭 사용)

select ename AS 이름, salary AS 인상 전 급여, AS 인상 후 급여 Salary+300 from employee

5. 사원명, 급여, 연간 총수입 + 상여금 $100을 적용하여 수입이 많은 순서로 정렬(별칭 사용)

select ename AS 이름, salary AS 급여, (salary*12)+100 AS 연간 총수입+상여금 from employee
order by salary desc;

6. 급여가 2000~3000 사이에 포함되는 사원명, 급여 출력

  • between 'A' and 'B' 사용
select ename, salary from employee
where between 2000 and 3000;
  • 대소비교 연산자 사용
select ename, salary from employee
where salary >= 2000 and salary <= 3000;

7. 1981년 2월 20일 ~ 1981년 5월 1일 사이에 입사한 사원명, 담당업무, 입사일을 출력하되 먼저 입사한 순서대로 정렬

select ename, job, hiredate from employee
where  hiredate between '81/02/20' and '18/05/01'
Order by hiredate desc ; 

8. 부서 번호가 20 또는 30에 속하는 사원명, 부서번호 출력하되 이름으로 오름차순 정렬

  • or 연산자 사용
select ename, dno from employee
where dno = 20 or dno = 30
Order by ename asc ; 
  • in 연산자 사용
select ename, dno from employee
where dno in(20,30)
Order by ename asc; 

9. 사원의 급여가 2000~3000 사이에 포함되고 부서번호가 20또는 30인 사원명, 급여, 부서번호 출력하되 이름으로 오름차순 정렬

select ename, salary, dno from employee
where salary between 2000 and 3000 and dno in(20,30)
Order by eno asc;

10. 1981년도 입사한 사원명, 입사일 출력하되 입사일 기준으로 오름차순 정렬

select ename, hiredate from employee
where hiredate like '81%'
Order by hiredate asc;

11. 관리자가 없는 사원명, 담당업무 출력

select ename, job from emlpoyee
where manager is null;  

12. 상여금을 받을 수 있는 사원명, 급여 , 상여금 출력하되 급여 기준으로 내림차순 정렬

select ename, salary, commission from employee
where commission is not null
Order by salary desc;

13. 이름의 3번째 문자가 'B'인 모든 사원명 출력

select ename from employee
where ename like '___B%';

14. 이름에 A와 E를 모두 포함하는 사원명, 급여, 담당업무 출력

select ename, salary, job from employee
where ename like '%A%' and ename like '%E%;

15. 담당업무가 사무원 또는 영업사원이면서 급여가 950. 1300. 1600이 아닌 사원명, 담당업무, 급여를 출력하되 사원명으로 내림차순 정렬

select ename, job, salary from employee
where job = salesman or job = clerk and salary not in (950, 1300, 1600)
order by ename desc;

마무리😁

중간 중간 헷갈리는 부분이있었지만 간단한 sql문은 where절과 연산자를 사용해서 잘 적을 수 있을 것 같다! 다만 막힘없이 나올 정도로 습득하려면 좀 더 연습이 필요 할 것 같다.!

profile
개발자 꿈나무

0개의 댓글