Oracle Database 10g SQL Fundamentals I - Practice 7
개발 및 관리/Oracle 9i, 10g, 11g, 12c, 19c 2012. 11. 13. 07:32
Oracle Database 10g SQL Fundamentals I - Practice 7
ar(11월9일 4차시)
Set Operators
- UNION ALL : 합집합 (중복 허용)
- UNION : 합집합 (중복 제거)
- INTERSECT : 교집합 (중복 제거)
- MINUS : 차집합 (중복 제거)
1.
SELECT DEPARTMENT_ID
FROM DEPARTMENTS
MINUS
SELECT DEPARTMENT_ID
FROM EMPLOYEES
WHERE JOB_ID = 'ST_CLERK';
2.
SELECT COUNTRY_ID,COUNTRY_NAME
FROM COUNTRIES
MINUS
SELECT C.COUNTRY_ID,C.COUNTRY_NAME
FROM COUNTRIES C, LOCATIONS L, DEPARTMENTS D
WHERE C.COUNTRY_ID = L.COUNTRY_ID
AND L.LOCATION_ID = D.LOCATION_ID
;
3.
COLUMN DUMMY NOPRINT
SELECT JOB_ID, DEPARTMENT_ID, 'X' DUMMY
FROM EMPLOYEES
WHERE DEPARTMENT_ID = 10
UNION
SELECT JOB_ID, DEPARTMENT_ID, 'Y' DUMMY
FROM EMPLOYEES
WHERE DEPARTMENT_ID = 50
UNION
SELECT JOB_ID, DEPARTMENT_ID, 'Y' DUMMY
FROM EMPLOYEES
WHERE DEPARTMENT_ID = 20
ORDER BY DUMMY
;
COLUMN DUMMY PRINT
4.
SELECT EMPLOYEE_ID, JOB_ID
FROM EMPLOYEES
INTERSECT
SELECT EMPLOYEE_ID, JOB_ID
FROM JOB_HISTORY
;
5.
1)
SELECT LAST_NAME, DEPARTMENT_ID, TO_CHAR(NULL)
FROM EMPLOYEES
UNION ALL
SELECT TO_CHAR(NULL), DEPARTMENT_ID, DEPARTMENT_NAME
FROM DEPARTMENTS
;
2)
SELECT LAST_NAME, DEPARTMENT_ID, TO_CHAR(NULL)
FROM EMPLOYEES
UNION
SELECT TO_CHAR(NULL), DEPARTMENT_ID, DEPARTMENT_NAME
FROM DEPARTMENTS
;
'개발 및 관리 > Oracle 9i, 10g, 11g, 12c, 19c' 카테고리의 다른 글
Oracle Database 10g SQL Fundamentals I - Practice 9 (0) | 2012.11.13 |
---|---|
Set Operators (0) | 2012.11.13 |
Oracle Database 10g SQL Fundamentals I - Practice 6 (0) | 2012.11.12 |
오라클 함수, LTRIM, TRANSLATE (0) | 2012.11.12 |
Oracle Database 10g SQL Fundamentals I - Practice 5 (0) | 2012.11.08 |