1. 커미션을 받는 직원에 대해 이름, 부서명, 근무지를 조회

select ename, dname, loc from emp INNER JOIN dept ON emp.deptno=dept.deptno where emp.comm IS NOT NULL;


2. 이름 중간에 L자가 있는 직원에 대해 이름, 업무, 부서명, 근무지 조회

select ename, job, dname, loc from emp INNER JOIN dept ON emp.deptno=dept.deptno where emp.ename like '%L%';


3. 각 직원들에 대해서 그들의 관리자보다 먼저 입사한 직원에 대해 이름, 입사일, 관리자이름, 관리자 입사일을 조회

select e1.ename, e1.hiredate as 직원입사, e2.hiredate as 관리자입사, e1.mgr, e2.ename from emp e1 INNER JOIN emp e2 ON e1.mgr = e2.empno where e1.hiredate <= e2.hiredate;


*4. 말단사원의 사번, 이름, 업무, 부서번호, 근무지를 조회

select empno, ename, job, emp.deptno, loc from emp right JOIN dept ON emp.deptno = dept.deptno where empno not in(select mgr from emp where mgr is not null);




*** 테이블을 하나 작성한다.(tblBook)

author title

-----------------------

최주현 하늘과 땅

최주현 바다

유은정 바다

박성우

최주현

박성우 천국

최지은 천국

최주현 천국

박성우 고슴도치

서금동


CREATE TABLE book(

author varchar2(15),

title varchar2(15)

);



INSERT INTO book VALUES('최주현','하늘과 땅');

INSERT INTO book VALUES('최주현','바다');

INSERT INTO book VALUES('유은정','바다');

INSERT INTO book VALUES('박성우','문');

INSERT INTO book VALUES('최주현','문');

INSERT INTO book VALUES('박성우','천국');

INSERT INTO book VALUES('최지은','천국');

INSERT INTO book VALUES('최주현','천국');

INSERT INTO book VALUES('박성우','고슴도치');

INSERT INTO book VALUES('서금동','나');


5. 한권의 책에 대해서 두명 이상의 작가가 쓴 책을 검색하시오.

예시) 책이름  작가명  작가명


select b1.title, b1.author 작가명1, b2.author 작가명2 from book b1 inner JOIN book b2 ON b1.title = b2.title and b1.author < b2.author;


6. 한권의 책에 대해서 세명의 작가가 쓴 책을 검색하시오.

예시) 책이름  작가명  작가명 작가명


select b1.title, b1.author 작가명1, b2.author 작가명2, b3.author 작가명3 from book b1 inner JOIN book b2 ON b1.title = b2.title inner join book b3 on b3.title = b2.title and b1.author < b2.author and b1.author > b3.author;

'DB > Oracle' 카테고리의 다른 글

[Oracle] Data Integrity(데이터 무결성)  (0) 2017.07.03
[Oracle] Transaction  (0) 2017.07.03
[Oracle] Join  (0) 2017.06.26
[Oracle 과제] select 문제 / SubQuery 문제  (0) 2017.06.26
[Oracle] SubQuery 중첩 쿼리 예제들  (0) 2017.06.26

+ Recent posts