반응형

[Oracle SQL] SELECT 실습_ 논리연산자



I 논리연산자 (AND, OR, NOT)

▶ 연산자 우선순위 : AND > OR



1. AND, OR 비교

1) AND


SELECT DEPTNO,ENAME,JOB,SAL FROM EMP WHERE DEPTNO=20 AND SAL>2500;





2) OR


SELECT DEPTNO,ENAME,JOB,SAL FROM EMP WHERE DEPTNO=20 OR SAL>2500;





2. 연산자 우선순위

1) AND ~ OR


SELECT DEPTNO,ENAME,JOB,SAL FROM EMP WHERE DEPTNO=20 AND SAL>2500 OR JOB='CLERK';





2) OR ~ AND


SELECT DEPTNO,ENAME,JOB,SAL FROM EMP WHERE SAL>2500 OR JOB='CLERK' AND DEPTNO>=20;





3) OR ~ ( ... AND ... )


SELECT DEPTNO,ENAME,JOB,SAL FROM EMP WHERE SAL>2500 OR (JOB='CLERK' AND DEPTNO>=20);





3. NOT

1) !=


SELECT DEPTNO,ENAME,JOB,SAL FROM EMP WHERE JOB != 'CLERK';





2) NOT IN


SELECT DEPTNO,ENAME,JOB,SAL FROM EMP WHERE JOB NOT IN ('CLERK','SALESMAN');



반응형