๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ—‚.๋Œ€์™ธํ™œ๋™/๐Ÿ“.์นด์นด์˜คํด๋ผ์šฐ๋“œ์Šค์ฟจ

[DB] DML ์—ฐ์Šต๋ฌธ์ œ

by ๐Ÿ’พ๊ณ ๊ตฌ๋งˆ๋ง›ํƒ•๋จน๊ณ ์‹ถ๋‹ค 2023. 12. 28.
728x90

๐ŸŒž ์˜ค๋ผํด๋กœ ๋ฐฐ์šฐ๋Š” ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๊ฐœ๋ก ๊ณผ ์‹ค์Šต ์—ฐ์Šต๋ฌธ์ œ

1 ๋งˆ๋‹น์„œ์ ์˜ ๊ณ ๊ฐ์ด ์š”๊ตฌํ•˜๋Š” ๋‹ค์Œ ์งˆ๋ฌธ์— ๋Œ€ํ•ด SQL ๋ฌธ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

  (1) ๋„์„œ๋ฒˆํ˜ธ๊ฐ€ 1์ธ ๋„์„œ์˜ ์ด๋ฆ„

  (2) ๊ฐ€๊ฒฉ์ด 20,000์› ์ด์ƒ์ธ ๋„์„œ์˜ ์ด๋ฆ„

  (3) ๋ฐ•์ง€์„ฑ์˜ ์ด ๊ตฌ๋งค์•ก(๋ฐ•์ง€์„ฑ์˜ ๊ณ ๊ฐ๋ฒˆํ˜ธ๋Š” 1๋ฒˆ์œผ๋กœ ๋†“๊ณ  ์ž‘์„ฑ)

  (4) ๋ฐ•์ง€์„ฑ์ด ๊ตฌ๋งคํ•œ ๋„์„œ์˜ ์ˆ˜(๋ฐ•์ง€์„ฑ์˜ ๊ณ ๊ฐ๋ฒˆํ˜ธ๋Š” 1๋ฒˆ์œผ๋กœ ๋†“๊ณ  ์ž‘์„ฑ)

SELECT BOOKNAME FROM BOOK WHERE BOOKID = 1;
SELECT BOOKNAME FROM BOOK WHERE PRICE >= 20000;
SELECT SUM(SALEPRICE) FROM ORDERS WHERE CUSTID = 1;
SELECT COUNT(*) FROM ORDERS WHERE CUSTID =1;

  

2 ๋งˆ๋‹น์„œ์ ์˜ ์šด์˜์ž์™€ ๊ฒฝ์˜์ž๊ฐ€ ์š”๊ตฌํ•˜๋Š” ๋‹ค์Œ ์งˆ๋ฌธ์— ๋Œ€ํ•ด SQL ๋ฌธ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

  (1) ๋งˆ๋‹น์„œ์  ๋„์„œ์˜ ์ด ๊ฐœ์ˆ˜

  (2) ๋งˆ๋‹น์„œ์ ์— ๋„์„œ๋ฅผ ์ถœ๊ณ ํ•˜๋Š” ์ถœํŒ์‚ฌ์˜ ์ด ๊ฐœ์ˆ˜

  (3) ๋ชจ๋“  ๊ณ ๊ฐ์˜ ์ด๋ฆ„, ์ฃผ์†Œ

  (4) 2014๋…„ 7์›” 4์ผ~7์›” 7์ผ ์‚ฌ์ด์— ์ฃผ๋ฌธ๋ฐ›์€ ๋„์„œ์˜ ์ฃผ๋ฌธ๋ฒˆํ˜ธ

  (5) 2014๋…„ 7์›” 4์ผ~7์›” 7์ผ ์‚ฌ์ด์— ์ฃผ๋ฌธ๋ฐ›์€ ๋„์„œ๋ฅผ ์ œ์™ธํ•œ ๋„์„œ์˜ ์ฃผ๋ฌธ๋ฒˆํ˜ธ

  (6) ์„ฑ์ด ‘๊น€’ ์”จ์ธ ๊ณ ๊ฐ์˜ ์ด๋ฆ„๊ณผ ์ฃผ์†Œ

  (7) ์„ฑ์ด ‘๊น€’ ์”จ์ด๊ณ  ์ด๋ฆ„์ด ‘์•„’๋กœ ๋๋‚˜๋Š” ๊ณ ๊ฐ์˜ ์ด๋ฆ„๊ณผ ์ฃผ์†Œ

SELECT COUNT(*) FROM BOOK;
SELECT PUBLISHER, COUNT(*) FROM BOOK GROUP BY PUBLISHER;
SELECT NAME, ADDRESS FROM CUSTOMER;
SELECT BOOKID FROM ORDERS WHERE ORDERDATE BETWEEN '2014/07/04' AND '2014/07/07' GROUP BY BOOKID;
SELECT BOOKID FROM ORDERS WHERE ORDERDATE NOT BETWEEN '2014/07/04' AND '2014/07/07' GROUP BY BOOKID;
SELECT NAME, ADDRESS FROM CUSTOMER WHERE NAME LIKE '๊น€%';
SELECT NAME, ADDRESS FROM CUSTOMER WHERE NAME LIKE '๊น€%์•„';
728x90