--조인 (가상테이블)
--흩어져있는 정보의 테이블중 내가 원하는 테이블의 컬럼명을 가져와 볼수있다
--등가 조인
--Q1. 학생명 학과번호 학과이름...student + department
select s.name 학생명, s.deptno1 학과번호, d.dname 학과명
from student s, department d
where s.deptno1=d.deptno;
--Q2. 학생명 교수번호 교수명
select s.name 학생명, p.profno 교수번호 ,p.name 지도교수명
from student s, professor p
where p.profno=s.profno;
--Q3. 학생명 학과명 지도교수명 (student + department + professor)
select s.name 학생명, d.dname 학과명, p.name 지도교수명
from student s, department d, professor p
where s.deptno1=d.deptno
and s.profno=p.profno;
--Q4. 사원명 부서명 (emp + dept)
select e.ename 사원명, d.dname 부서명
from emp e, dept d
where e.deptno = d.deptno;
--Q5. 제과명 단가 판매개수 판매가격 ( panmae + product )
select p.p_name 제과명, p.p_price 단가, pa.p_qty 판매개수, pa.p_total 판매가격
from panmae pa, product p
where pa.p_code=p.p_code;
--비등가 조인
--등가조인이란건 같은조건(=) 을 조인해서 가지고 오는것
--등가가 아닌 조건이 크거나 같다 (>=) 작거나 같다 (<=) 이런걸 비등가조인
--Q6. gogak 테이블과 gift 테이블을 조인하여 고객에 포인트 별로 받을수있는 상품을 조회한후 출력
--고객명 포인트 상품명
select g.gname 고객명, g.point 포인트, gi.gname 상품명
from gogak g, gift gi
where g.point between gi.g_start and gi.g_end;
'DB > 오라클 SQL문' 카테고리의 다른 글
25. ★ 시퀀스 | 테이블 | 상품추가 | primary key | CONSTRAINT | REFERENCES | 조인 방법 3개 ★ (0) | 2022.02.23 |
---|---|
25. CONSTRAINT | check 제약조건 생성, 삭제 | L999,999,999 | UNIQUE (0) | 2022.02.23 |
25. 서브쿼리(쿼리안에 또다른 쿼리 담김) | 문제 7개 (0) | 2022.02.23 |
25. Rollup( group by 절에 조건으로 소계값) | Cube (각 소계와 전체총계까지) (0) | 2022.02.23 |
25. 어제 복습문제 9개 (0) | 2022.02.23 |