본문으로 바로가기
728x90
반응형

 

 

오라클 SQL과 PL/SQL | 서진수 - 교보문고

오라클 SQL과 PL/SQL | SQL과 PL/SQL에 대한 가장 쉽고 친절한 입문서SQL과 PL/SQL에 대한 내용은 방대하며 어려운 내용들이 많기 때문에 처음 공부하는 학습자는 스스로 공부하기가 쉽지 않다. 이 책은

product.kyobobook.co.kr

 

 

연습문제 1번 pg.212

 

emp 테이블을 사용하여 사원 중에서 급여(sal)와 보너스(comm)를 합친 금액이 가장많은 경우와 가장 적은 경우, 평균 금액을 구하세요. 단, 보너스가 없을 경우는 보너스를 0 으로 계산하고 출력 금액은 모두 소수점 첫째 자리까지만 나오게 하세요.

 

SQL

 

 

반응형

 

 

1
2
3
4
select max(sal+nvl(comm, 0)) "MAX",
       min(sal+nvl(comm, 0)) "MIN",
       round(avg(sal+nvl(comm, 0)), 1"AVG"
from emp;
cs

 

 

 

실행 결과

 

 


 

연습문제 2번 pg.212

 

student테이블의 birthday컬럼을 참조해서 아래와 같이 월별로 생일자 수를 출력하세요.

 

SQL

 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
select count(birthday)||'EA' "TOTAL",
       count(decode(substr(birthday, 42), '01''0'))||'EA' "JAN",
       count(decode(substr(birthday, 42), '02''0'))||'EA' "FEB",
       count(decode(substr(birthday, 42), '03''0'))||'EA' "MAR",
       count(decode(substr(birthday, 42), '04''0'))||'EA' "APR",
       count(decode(substr(birthday, 42), '05''0'))||'EA' "MAY",
       count(decode(substr(birthday, 42), '06''0'))||'EA' "JUN",
       count(decode(substr(birthday, 42), '07''0'))||'EA' "JUL",
       count(decode(substr(birthday, 42), '08''0'))||'EA' "AUG",
       count(decode(substr(birthday, 42), '09''0'))||'EA' "SEP",
       count(decode(substr(birthday, 42), '10''0'))||'EA' "OCT",
       count(decode(substr(birthday, 42), '11''0'))||'EA' "NOV",
       count(decode(substr(birthday, 42), '12''0'))||'EA' "DEC"
from student;
cs

 

 

실행 결과

 

 


연습문제 3번 pg.213

 

Student 테이블의 tel 컬럼을 참고하여 아래와 같이 지역별 인원수를 출력하세요. 단, 02-SEOUL, 031-GYEONGGI, 051--BUSAN, 052-ULSAN, 053-DAEGU, 055-GYEONGANM으로 출력하세요.

 

SQL

 

 


 

1
2
3
4
5
6
7
8
select count(tel) "TOTAL",
       count(decode(substr(tel, 1, instr(tel, ')')-1), '02''0')) "SEOUL",
       count(decode(substr(tel, 1, instr(tel, ')')-1), '031''0')) "GYEONGGI",
       count(decode(substr(tel, 1, instr(tel, ')')-1), '051''0')) "BUSAN",
       count(decode(substr(tel, 1, instr(tel, ')')-1), '052''0')) "ULSAN",
       count(decode(substr(tel, 1, instr(tel, ')')-1), '053''0')) "DAEGU",
       count(decode(substr(tel, 1, instr(tel, ')')-1), '055''0')) "GYEONGNAM"
from student;
cs

 

 

실행 결과

 

 


 

 

연습문제 4번 pg.213

 

먼저 emp 테이블에 아래 두건의 데이터를 입력한 후 작업하세요. emp테이블을 사용하여 아래의 화면과 같이 부서별로 직급별로 급여 합계 결과를 출력하세요.

 

SQL

 


1
2
3
4
5
6
7
8
9
10
select deptno,
       sum(decode(job, 'CLERK', sal, 0)) "CLERK",
       sum(decode(job, 'MANAGER', sal, 0)) "MANAGER",
       sum(decode(job, 'PRESIDENT', sal, 0)) "PRESIDENT",
       sum(decode(job, 'ANALYST', sal, 0)) "ANALYST",
       sum(decode(job, 'SALESMAN', sal, 0)) "SALESMAN",
       sum(nvl2(job, sal, 0)) "TOTAL"
from emp
group by rollup(deptno)
order by deptno;
cs

 

 

실행 결과

 

 


 

728x90
반응형