728x90
반응형
연습문제 1 pg.258
1. 학생 테이블(student)과 학과 테이블(department) 을 사용하여 학생이름, 1전공 학과번호(deptno1), 1전공학과 이름을 출력하세요(ANSI join 문법과 Oracle join 문법으로 각각 SQL을 작성하세요.
SQL
반응형
1
2
3
4
|
select s.name, s.deptno1, d.dname
from student s, department d
where s.deptno1 = d.deptno
order by s.studno;
|
cs |
1
2
3
4
|
select s.name, s.deptno1, d.dname
from student s join department d
on s.deptno1 = d.deptno
order by s.studno;
|
cs |
실행 결과
연습문제 2 pg.258
emp2테이블과 p_grade 테이블을 조회하여 현재 직급이 있는 사원의 이름과 직급, 현재 연봉, 해당 직급의 연봉의 하한 금액과 상한 금액을 아래 결과 화면과 같이 출력하세요.
SQL
1
2
3
4
5
|
select e.name, e.position, to_char(e.pay, '999,999,999') "PAY",
to_char(p.s_pay, '999,999,999') "Low PAY",
to_char(p.e_pay, '999,999,999') "High PAY"
from emp2 e join p_grade p
on e.position = p.position;
|
cs |
1
2
3
4
5
|
select e.name, e.position, to_char(e.pay, '999,999,999') "PAY",
to_char(p.s_pay, '999,999,999') "Low PAY",
to_char(p.e_pay, '999,999,999') "High PAY"
from emp2 e, p_grade p
where e.position = p.position;
|
cs |
실행 결과
연습문제 3 pg.259
emp2 테이블과 p_grade테이블을 조회하여 사원들의 이름과 나이, 현재직급, 예상 직급을 출력하세요. 예상 직급은 나이로 계산하며 해당 나이가 받아야 하는 직급을 의미합니다. 나이는 오늘 (sysdate)을 기준으로 하되 trunc로 소수점 이하는 절삭해서 계산하세요.
SQL
1
2
3
4
5
|
select e.name, trunc(months_between(sysdate, e.birthday) / 12) "AGE" ,
e.position "CURR_POSITION", p.position "BE_POSITION"
from emp2 e, p_grade p
where trunc(months_between(sysdate, e.birthday) / 12) >= p.s_age
and trunc(months_between(sysdate, e.birthday) / 12) <= p.e_age;
|
cs |
1
2
3
4
5
|
select e.name, trunc(months_between(sysdate, e.birthday) / 12) "AGE" ,
e.position "CURR_POSITION", p.position "BE_POSITION"
from emp2 e join p_grade p
on trunc(months_between(sysdate, e.birthday) / 12) >= p.s_age
and trunc(months_between(sysdate, e.birthday) / 12) <= p.e_age;
|
cs |
실행 결과
연습문제 4 pg. 259
customer 테이블과 gift 테이블을 join 하여 고객이 자기 포인트보다 낮은 포인트의 상품중 한가지를 선택할수 있다고 할때 notebook 을 선택할수 있는 고객명과 포인트, 상품명을 출력하세요
SQL
1
2
3
4
5
6
|
select c.gname, c.point, g.gname "Notebook"
from customer c, gift g
where c.point>=g.g_start
and g.gname = 'Notebook';
|
cs |
1
2
3
4
5
|
select c.gname, c.point, g.gname "Notebook"
from customer c join gift g
on c.point>=g.g_start
and g.gname = 'Notebook';
|
cs |
실행 결과
728x90
반응형
'[SQL]다양한 예제로 쉽게 배우는 오라클 > 4장' 카테고리의 다른 글
[다양한 예제로 쉽게] 4장 연습문제 pg.260~261 (0) | 2023.01.09 |
---|