반응형
use madangdb;
-- 고객과 고객의 주문에 관한 데이터를 모두 조회
use madangdb;
select * from
customertbl c inner join orderstbl od
on c.cusid= od.cusid
order by c.cusid;
-- 박지성의 고객아이디와 이름, 주소, 구매액, 구매날짜를 조회
SELECT
c.cusid, c.name, c.address, od.saleprice, od.orderdate
FROM
customertbl c
INNER JOIN
orderstbl od ON c.cusid = od.cusid
WHERE
c.cusid = 1;
-- 고객별로 이름과 주소와 총 구매액을 조회
SELECT
c.name, c.address, sum(od.saleprice)
FROM
customertbl c
INNER JOIN
orderstbl od ON c.cusid = od.cusid
group by c.cusid;
-- 가격이 20,000원이상인 도서를 주문한 고객의 이름과 도서의 이름 조회
SELECT
c.name, b.bookname, b.price
FROM
customertbl c
INNER JOIN
orderstbl od ON c.cusid = od.cusid
inner join booktbl b on b.bookid = od.bookid
where b.price >= 20000;
-- 정가보다 싸게 산 고객의 아이디, 이름, 구매가격을 조회
SELECT
c.cusid, c.name, od.saleprice
FROM
customertbl c
INNER JOIN
orderstbl od ON c.cusid = od.cusid
inner join booktbl b on b.bookid = od.bookid
where b.price > od.saleprice;
-- cookdb
-- KYM이라는 아이디를 가진 회원이 구매한 물건과 회원 정보 조회(아이디, 이름, 물품, 물품 가격, 주소, 연락처)
use cookdb;
select u.userid, u.username, u.addr, b.prodname, b.price, concat(u.mobile1 , u.mobile2) as '연락처'
from usertbl u inner join buytbl b
on u.userid = b.userid
where u.userid = 'kym';
-- 경북에 거주하는 유저들의 아이디, 이름, 구매물품, 구매액을 조회
use cookdb;
select u.userid, u.username, u.addr, b.prodname, b.price, concat(u.mobile1 ,u.mobile2) as 연락처
from usertbl u inner join buytbl b
on u.userid = b.userid
where u.addr= '경북';
-- 경북에 거주하거나 물품 분류가 없는 물건을 구입한 유저들의 아이디, 이름, 구매물품, 주소를 조회
use cookdb;
select u.userid, u.username, u.addr, b.prodname, b.price, concat(u.mobile1 ,u.mobile2) as 연락처
from usertbl u inner join buytbl b
on u.userid = b.userid
where u.addr= '경북' or b.groupname is null;
이것도 테이블이 있어야 정확히 이해가나, 제가 테이블 예제를 안올렸으니 문법이 어떤 것이다. 하고 확인만 하시면 됩니다.
반응형
'It Study > 코딩테스트 연습' 카테고리의 다른 글
프로그래머스 lv1 - 약수의 합 (0) | 2024.09.30 |
---|---|
프로그래머스 lv1 - x만큼 간격이 있는 n개의 숫자 (0) | 2024.09.23 |
프로그래머스 lv1 - 문자열을 정수로 바꾸기 (0) | 2024.09.22 |
프로그래머스 lv1 - 평균 구하기 (0) | 2024.09.18 |
프로그래머스 lv1 - 짝수와 홀수 (0) | 2024.09.18 |