1. ๋ง๋น์์ ์ ๊ณ ๊ฐ์ด ์๊ตฌํ๋ ๋ค์ ์ง๋ฌธ์ ๋ํด SQL ๋ฌธ์ ์์ฑํ์์ค.
(5) ๋ฐ์ง์ฑ์ด ๊ตฌ๋งคํ ๋์์ ์ถํ์ฌ ์
(6) ๋ฐ์ง์ฑ์ด ๊ตฌ๋งคํ ๋์์ ์ด๋ฆ, ๊ฐ๊ฒฉ, ์ ๊ฐ์ ํ๋งค๊ฐ๊ฒฉ์ ์ฐจ์ด
(7) ๋ฐ์ง์ฑ์ด ๊ตฌ๋งคํ์ง ์์ ๋์์ ์ด๋ฆ
-- 5.
SELECT PUBLISHER
FROM BOOK
WHERE BOOKID IN (SELECT BOOKID
FROM ORDERS
WHERE CUSTID=1);
-- 6.
SELECT CS.NAME, BK.BOOKNAME, BK.PRICE, BK.PRICE - OD.SALEPRICE "์ฐจ์ด"
FROM CUSTOMER CS, ORDERS OD, BOOK BK
WHERE CS.CUSTID = OD.CUSTID AND
OD.BOOKID = BK.BOOKID AND CS.CUSTID = 1;
-- 7.
SELECT BOOKNAME
FROM BOOK
MINUS
SELECT BOOKNAME
FROM BOOK
WHERE BOOKID IN (SELECT BOOKID
FROM ORDERS
WHERE CUSTID=1);
2. ๋ง๋น์์ ์ ์ด์์์ ๊ฒฝ์์๊ฐ ์๊ตฌํ๋ ๋ค์ ์ง๋ฌธ์ ๋ํด SQL ๋ฌธ์ ์์ฑํ์์ค.
(8) ์ฃผ๋ฌธํ์ง ์์ ๊ณ ๊ฐ์ ์ด๋ฆ(๋ถ์์ง์ ์ฌ์ฉ)
(9) ์ฃผ๋ฌธ ๊ธ์ก์ ์ด์ก๊ณผ ์ฃผ๋ฌธ์ ํ๊ท ๊ธ์ก
(10) ๊ณ ๊ฐ์ ์ด๋ฆ๊ณผ ๊ณ ๊ฐ๋ณ ๊ตฌ๋งค์ก
(11) ๊ณ ๊ฐ์ ์ด๋ฆ๊ณผ ๊ณ ๊ฐ์ด ๊ตฌ๋งคํ ๋์ ๋ชฉ๋ก
(12) ๋์์ ๊ฐ๊ฒฉ(Book ํ ์ด๋ธ)๊ณผ ํ๋งค๊ฐ๊ฒฉ(Orders ํ ์ด๋ธ)์ ์ฐจ์ด๊ฐ ๊ฐ์ฅ ๋ง์ ์ฃผ๋ฌธ
(13) ๋์์ ํ๋งค์ก ํ๊ท ๋ณด๋ค ์์ ์ ๊ตฌ๋งค์ก ํ๊ท ์ด ๋ ๋์ ๊ณ ๊ฐ์ ์ด๋ฆ
-- 8.
SELECT NAME
FROM CUSTOMER
WHERE CUSTID NOT IN (SELECT CUSTID
FROM ORDERS);
-- 9.
SELECT SUM(SALEPRICE) "์ฃผ๋ฌธ์ด์ก" , AVG(SALEPRICE) "์ฃผ๋ฌธํ๊ท "
FROM ORDERS;
-- 10.
SELECT CUSTID, NAME, (SELECT SUM(SALEPRICE)
FROM ORDERS OD
WHERE OD.CUSTID = CS.CUSTID) "๊ตฌ๋งค์ก"
FROM CUSTOMER CS
GROUP BY CUSTID, NAME
ORDER BY CUSTID;
-- 11.
SELECT CS.NAME, BK.BOOKNAME
FROM CUSTOMER CS, ORDERS, BOOK BK
WHERE CS.CUSTID = ORDERS.CUSTID AND
ORDERS.BOOKID = BK.BOOKID
ORDER BY NAME;
-- 12.
SELECT OD.ORDERID, MAX(BK.PRICE-OD.SALEPRICE) "ํฐ์ฐจ์ด"
FROM ORDERS OD, BOOK BK
WHERE OD.BOOKID = BK.BOOKID AND
BK.PRICE-OD.SALEPRICE = (SELECT MAX(BK.PRICE-OD.SALEPRICE)
FROM ORDERS OD , BOOK BK
WHERE OD.BOOKID = BK.BOOKID)
GROUP BY OD.ORDERID;
-- 13.
SELECT CS.NAME, AVG(OD.SALEPRICE)
FROM CUSTOMER CS, ORDERS OD
WHERE CS.CUSTID = OD.CUSTID
GROUP BY CS.NAME
HAVING AVG(OD.SALEPRICE) > (SELECT AVG(SALEPRICE) FROM ORDERS);
'๐.๋์ธํ๋ > ๐.์นด์นด์คํด๋ผ์ฐ๋์ค์ฟจ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[DB] ๋ทฐ VIEW (0) | 2024.01.03 |
---|---|
[DB] ์ ๊ทํ (0) | 2024.01.02 |
[DB] ๋ถ์ ์ง์(subquery) (0) | 2023.12.29 |
[DB] DML ์ฐ์ต๋ฌธ์ (1) | 2023.12.28 |
[JAVA] ์์ธ Exception (0) | 2023.12.20 |