Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- rs.next()
- 삼항 연산식
- interface
- 상속
- 다형성
- 중첩for문
- 문자열
- javascript
- docker
- 이클립스
- 이중 배열
- scanner
- for문
- 인터페이스
- 상수
- jsp
- 2차원 배열
- 오버로딩
- 삼항 연산
- 배열
- 자바
- Else If
- extends
- If
- Integer.MIN_VALUE
- super()
- arraylist
- 메소드
- Integer.MAX_VALUE
- Break
Archives
- Today
- Total
개발로드
[MySQL]JOIN 기초 연습예제 본문
use jointestdb;
1) porderTBL 테이블과 productTBL테이블을 이용해서 판매금액을 구하기
orderid, pcode, amount(수량), price(가격), 판매금액(수량 * 가격), pname(제품명), region(원산지)
select orderid, po.pcode, amount as 수량, price as 가격, format((amount*price),0) as 판매금액, pname as 제품명, region as 원산지
from pordertbl po join producttbl pd
on po.pcode = pd.pcode;
2) porderTBL 테이블과 productTBL테이블을 이용해서 pname, 주문금액(수량 * 단가)
판매수량(amount)을 검색하되, 판매수량이 50이상인 것만
where 조건이용
select pname, format((amount*price),0) as 판매금액, amount as 판매수량
from pordertbl po join producttbl pd
on po.pcode = pd.pcode
where amount>=50;
3) porderTBL 테이블, productTBL테이블, customerTBL 테이블을 이용하여
주소가 강남으로 끝나고, amount가 50이하인 자료를 찾아
orderDate, amount, pname, cname을 검색하시오.
select orderdate, amount, pname, cname, address
from pordertbl po join producttbl pd join customertbl ct
on po.pcode=pd.pcode and po.custid = ct.custid
where amount<=50 and address like '%강남';
4) porderTBL 테이블에서 판매수량이 가장 많은 제품의 최고 판매수량과 pcode를 검색
select pcode, amount from pordertbl where amount=(select max(amount) from pordertbl);
porderTBL 테이블에서 판매수량이 가장 많은 제품의 판매수량
select max(amount) from pordertbl;
-- 하위질의문 = 부속질의문 = subquery
-- 쿼리문 안에 또다른 쿼리문을 삽입
-- 실행은 하위 쿼리부터 실행 됨
마치며
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]JOIN 기초 연습 예제_2 (0) | 2024.02.13 |
|---|---|
| [MySQL]delete/update 기초 연습 예제 (0) | 2024.02.13 |
| [MySQL]select 기초 연습예제 (1) | 2024.02.06 |
| [MySQL]온라인 쇼핑 주문 목록 데이터베이스 만들기 (0) | 2024.02.01 |