| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | |||||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| 31 |
- 문자열
- 삼항 연산식
- Break
- Integer.MIN_VALUE
- 상수
- jsp
- extends
- 인터페이스
- 자바
- for문
- Else If
- scanner
- 다형성
- 메소드
- 오버로딩
- arraylist
- super()
- 2차원 배열
- 중첩for문
- Integer.MAX_VALUE
- docker
- javascript
- 상속
- 이중 배열
- If
- 삼항 연산
- interface
- 이클립스
- 배열
- rs.next()
- Today
- Total
개발로드
[MySQL]JOIN 기초 연습 예제_2 본문
1) pordertbl과 producttbl테이블을 이용해서 orderDate, pcode,
-- pname, amount, 판매가격( amount * price)을 조회
select orderDate, od.pcode, pname, amount, format((amount*price),0) as 판매가격
from pordertbl as od join producttbl as pd
on od.pcode = pd.pcode;
2) pordertbl 테이블과 customertbl 테이블을 이용
-- 주문자(cname), 주문일자(orderdate), 개수(amount), 주소(address)를 조회
select cname as 주문자, orderdate as 주문일자, amount as 개수, address as 주소
from pordertbl as od join customertbl as ct
on od.custid = ct.custid;
3) pordertbl 테이블과 customertbl 테이블을 이용
-- cname 이 '김태연'인 사람이 주문한 제품을 검색
-- 주문자(cname), 주문일자(orderdate), 개수(amount), 주소(address)를 조회
select cname as 주문자, orderdate as 주문일자, amount as 개수, address as 주소
from pordertbl as od join customertbl as ct
on od.custid = ct.custid
where cname = '김태연';
4) pordertbl 테이블, cutomertbl 테이블, producttbl 테이블을 모두 이용
-- 주문자(cname), 주문일자(orderdate), 상품명(pname), 주문수량(amount), 주문금액(amount * price)
-- 주문수량이 30개이상인 자료만 주문일자별로 오름차순 정렬하여 조회
select cname as 주문자, orderdate as 주문일자, pname as 상품명, amount as 주문수량, format((amount*price),0) as 주문금액
from pordertbl as ot join customertbl as ct
on ot.custid = ct.custid
join producttbl as pt
on ot.pcode = pt.pcode
where amount >= 30
order by orderdate asc;
5) pordertbl 테이블과 customertbl테이블을 이용하여
-- left outer join과 right outer join을 비교
1) left outer join
select * from pordertbl as pt left outer join customertbl as ct on pt.custid=ct.custid;
2) right outer join
select * from pordertbl as pt right outer join customertbl as ct on pt.custid = ct.custid;
마치며
MySQL의 Join의 간단한 예제를 풀어보았습니다.
여유가 되신다면 제 GitHub에 오셔서 좋은 코드들을 구경해주세요!

https://github.com/gimpo5975?tab=repositories
gimpo5975 - Overview
gimpo5975 has 2 repositories available. Follow their code on GitHub.
github.com
'SQL' 카테고리의 다른 글
| [MySQL]delete/update 기초 연습 예제 (0) | 2024.02.13 |
|---|---|
| [MySQL]JOIN 기초 연습예제 (0) | 2024.02.08 |
| [MySQL]select 기초 연습예제 (1) | 2024.02.06 |
| [MySQL]온라인 쇼핑 주문 목록 데이터베이스 만들기 (0) | 2024.02.01 |