수업(국비지원)/Oracle
[Oracle] in, not in 연산자
byeolsub
2023. 4. 13. 13:11
- in 연산자
: 조회 대상이 되는 값을 선택.
select 컬럼명,.. from 테이블명 where 컬럼명 in(A,B);
예시 : 학생 중 101학과, 201학과 학생의 이름,부서코드,학년 조회하기
select naem,deptno1,grade from student where deptno1 in(101,201);
select name,deptno1,grade from student where deptno1=101 or deptno1=201;
문제 : 101,201학과 학생 중 키가 170이상 180이하인 학생의
학번,이름,몸무게,키,학과코드 조회하기
select studno,name,weight,height,deptno1 from student where height between 170 and 180
and deptno1 in(101,201);
💡
where은 한번만 들어가야한다. 두개 조건을 충족해야 하므로 and 사용하여 묶어줌.
- not in 연산자
: 연산자의 내용을 제외하고 조회하고 싶을 때 사용
select 컬럼명,.. from 테이블명 where 컬럼명 not in(A,B);
예시 : 사원테이블에서 부서코드가 10,30이 아닌 부서에서 근무하는 사원의
이름,부서코드,급여 조회하기
select ename,deptno,sal from emp where deptno not in (10,30);