Giter VIP home page Giter VIP logo

1. ํ”„๋กœ์ ํŠธ ์„ค๋ช…

The project was carried out using the concepts learned in the major class "DB Design and Implementation", and the final goal of the project is to interview real companies that need database systems, design databases based on their requirements, and derive several SQLs using the database. The number of participants in the project is 4, and I managed the overall progress as a team leader and was in charge of interviews with corporate officials & ERD design & SQL.
์ „๊ณต ์ˆ˜์—… 'DB ์„ค๊ณ„ ๋ฐ ๊ตฌํ˜„'์—์„œ ๋ฐฐ์› ๋˜ ๊ฐœ๋…๋“ค์„ ํ™œ์šฉํ•˜์—ฌ ์ง„ํ–‰ํ•œ ํ”„๋กœ์ ํŠธ๋กœ, ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์‹œ์Šคํ…œ์„ ํ•„์š”๋กœ ํ•˜๋Š” ์‹ค์ œ ๊ธฐ์—…์„ ์ธํ„ฐ๋ทฐํ•˜๊ณ  ๊ทธ๋“ค์˜ ์š”๊ตฌ์‚ฌํ•ญ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์„ค๊ณ„ํ•˜๊ณ , ํ•ด๋‹น ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ํ™œ์šฉํ•œ ๋ช‡๊ฐ€์ง€์˜ SQL์„ ๋„์ถœํ•˜๋Š” ๊ฒƒ์ด ํ”„๋กœ์ ํŠธ ์ตœ์ข… ๋ชฉํ‘œ์ด๋‹ค. ํ”„๋กœ์ ํŠธ ์ฐธ์—ฌ ์ธ์›์€ 4๋ช…์ด๋ฉฐ, ๋ณธ์ธ์€ ํŒ€์žฅ์œผ๋กœ ์ „์ฒด์ ์ธ ์ง„ํ–‰ ์ƒํ™ฉ์„ ๊ด€๋ฆฌํ•˜๊ณ , ๊ธฐ์—… ๊ด€๊ณ„์ž ์ธํ„ฐ๋ทฐ & ERD ์„ค๊ณ„ & SQL ์„ ๋‹ด๋‹นํ–ˆ๋‹ค.

2. ์„ ์ • ๊ธฐ์—…

'A์‚ฌ(๊ธฐ์—… ๊ด€๊ณ„์ž๋ถ„์˜ ์š”์ฒญ์œผ๋กœ ๊ธฐ์—… ์ด๋ฆ„์€ ์ต๋ช… ์ฒ˜๋ฆฌ)'๋Š” ๋ธ”๋ Œ๋”ฉ ํ‹ฐ๋ฅผ ํŒ๋งคํ•˜๋Š” ์ž‘์€ ๊ทœ๋ชจ์˜ ์Šคํƒ€ํŠธ์—… ๊ธฐ์—…์ด๋‹ค. ๋ธ”๋ Œ๋”ฉ ํ‹ฐ๋ž€ ๊ธฐ๋ณธ์ ์œผ๋กœ ์กด์žฌํ•˜๋Š” ์ฐจ (e.g., ๋…น์ฐจ,์บ๋ชจ๋งˆ์ผ)์— ๋‹ค๋ฅธ ์ฐจ๋‚˜ ์žฌ๋ฃŒ๋“ค์„ ์„ž์–ด ํƒ„์ƒํ•œ ์ƒˆ๋กœ์šด ํ’๋ฏธ์˜ ์ฐจ์ธ๋ฐ, ์ด ๊ธฐ์—…์˜ ํŠน์ด์ ์€ ๋ธ”๋ Œ๋”ฉ ํ‹ฐ๋ฅผ ํ•œ๊ตญ์— ๊ฑฐ์ฃผํ•˜๊ณ  ์žˆ๋Š” ์•„๋ž์ธ๋“ค์ด ๋งŒ๋“ ๋‹ค๋Š” ์ ์ด๋‹ค. A์‚ฌ๋Š” ๋ธ”๋ Œ๋”ฉ ํ‹ฐ์˜ ์›๋ฃŒ๊ฐ€ ๋˜๋Š” ์žฌ๋ฃŒ๋“ค์„ ๊ณต๊ธ‰์—…์ฒด๋กœ๋ถ€ํ„ฐ ๊ตฌ๋น„ํ•˜๊ณ , ์ด ์žฌ๋ฃŒ๋ฅผ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์•„๋ž์ธ ๋ธ”๋ Œ๋”๋“ค์ด ์ œ์ž‘ํ•œ ๋ธ”๋ Œ๋”ฉ ํ‹ฐ๋ฅผ ํŒ๋งคํ•˜๋ฉฐ, ๋ธ”๋ Œ๋”์—๊ฒŒ ์ธ์„ผํ‹ฐ๋ธŒ๋‚˜ ๋กœ์—ดํ‹ฐ๋ฅผ ์ฃผ๋Š” ์‹์œผ๋กœ ๋น„์ฆˆ๋‹ˆ์Šค๋ฅผ ํ•˜๊ณ  ์žˆ๋‹ค. ์•„๋ž˜๋Š” A์‚ฌ๊ฐ€ ์šฐ๋ฆฌ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์„ค๊ณ„ ํŒ€์—๊ฒŒ ์š”๊ตฌํ•˜๋Š” Business rules & Requirements์ด๋‹ค.

3. User Requirements & Business Rules

  1. ๊ณ ๊ฐ(Customer)์˜ ์œ ํ˜•์€ ๋น„ํšŒ์›, ์ •ํšŒ์›(Regular), ๊ตฌ๋…ํšŒ์›(Subscriber)๋กœ ๋‚˜๋‰œ๋‹ค. ๋น„ํšŒ์›์€ ์ •ํšŒ์›์ด๋‚˜ ๊ตฌ๋…ํšŒ์› ๋ชจ๋‘์— ์†ํ•˜์ง€ ์•Š๋Š” ๊ณ ๊ฐ์ด๋ฉฐ, ๊ตฌ๋…ํšŒ์›๊ณผ ์ •ํšŒ์›์€ ๋‹น์—ฐํžˆ ๊ฒธํ•  ์ˆ˜ ์žˆ๋‹ค. ๋ชจ๋“  ๊ณ ๊ฐ์€ ๊ณตํ†ต์ ์œผ๋กœ ID(unique identifier), Name, Address(์‹œ/๋™/ํ˜ธ), PhoneNumber(์—ฌ๋Ÿฌ๊ฐœ ์—ฐ๋ฝ์ฒ˜ ๊ธฐ์žฌ ๊ฐ€๋Šฅ), Gender, Birth Date์™€ ๋กœ๊ทธ์ธ์‹œ ํ•„์š”ํ•œ Login ID, Login Password ์ •๋ณด๋ฅผ ์ €์žฅํ•œ๋‹ค. ๋ฉ”๋ชจ) ๋น„ํšŒ์›์ผ ๊ฒฝ์šฐ์— ์ด Login ID, Login Password๊ฐ€ Null์ด๋‚˜ ํœด๋Œ€์ „ํ™” ๋ฒˆํ˜ธ ๋“ฑ์œผ๋กœ ๋Œ€์ฒด๋  ์ˆ˜ ์žˆ๋‹ค. 1-1. ์ •ํšŒ์›(Regular)์˜ ๊ฒฝ์šฐ ๊ตฌ๋งค ๋“ฑ์˜ ํ™œ๋™์„ ํ• ๋•Œ๋งˆ๋‹ค ์Œ“์ด๊ฒŒ ๋  ๋งˆ์ผ๋ฆฌ์ง€(ํฌ์ธํŠธ)๋ฅผ Point์— ์ €์žฅํ•˜๊ฒŒ ๋œ๋‹ค. ๋น„ํšŒ์›์˜ ๊ฒฝ์šฐ ์ •๊ทœํšŒ์›์ด ์•„๋‹ˆ๋‹ˆ ์ด๋Ÿฌํ•œ ํ˜œํƒ์„ ๋ฐ›์„ ์ˆ˜ ์—†๊ฒŒ ํ•ด์•ผ ํ•˜๋ฉฐ, ๊ตฌ๋…์ž์˜ ๊ฒฝ์šฐ ๋ถˆ๊ทœ์น™์ ์œผ๋กœ ๊ตฌ๋งค๊ธˆ์•ก์— ๋น„๋ก€ํ•˜์—ฌ ํฌ์ธํŠธ๋ฅผ ๋ฐ›๋Š” ์ •ํšŒ์›๊ณผ ๋‹ฌ๋ฆฌ ๊พธ์ค€ํžˆ ์ •์•ก์ œ๋กœ ๊ฒฐ์ œํ•˜๋ฏ€๋กœ ๊ตฌ๋… ํ™œ๋™์— ์žˆ์–ด ์ด๋Ÿฌํ•œ ํฌ์ธํŠธ๋Š” ์ œ๊ณต๋˜์ง€ ์•Š๊ฒŒ ํ•ด๋‹ฌ๋ผ๋Š” ๊ฒƒ์ด A์‚ฌ์˜ ์š”๊ตฌ์ด๋‹ค.(๋‹ค๋งŒ ๊ตฌ๋…ํšŒ์›์ผ ์ง€๋ผ๋„ ์ผ๋ฐ˜ํšŒ์›์œผ๋กœ์„œ ๋ณ„๋„ ๊ตฌ๋งค๋ฅผ ํ•  ๋•Œ์—๋Š” ํฌ์ธํŠธ๊ฐ€ ์ ๋ฆฝ๋œ๋‹ค.) 1-2. ๊ตฌ๋…ํšŒ์›(SubScriber)์€ ์ •๊ธฐ์ ์ธ ๊ฒฐ์ œ๊ฐ€ ํ•„์š”ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์‹ ์šฉ์นด๋“œ ๋ฒˆํ˜ธ(CreditCard Number)๋ฅผ ์ €์žฅํ•ด์•ผ ํ•œ๋‹ค. ๊ฐ๊ฐ์˜ ๊ตฌ๋…ํšŒ์›์€ ํ•˜๋‚˜์˜ ๊ตฌ๋…์ œ(Rate_Plan)๋ฅผ ์„ ํƒํ•˜์—ฌ ๊ตฌ๋…ํ• ์ˆ˜ ์žˆ์œผ๋ฉฐ, ๊ฐ๊ฐ์˜ ๊ตฌ๋…์ œ๋Š” ์—ฌ๋Ÿฌ ๊ตฌ๋…ํšŒ์›๋“ค์—๊ฒŒ ๊ตฌ๋…๋˜์–ด์งˆ ์ˆ˜ ์žˆ๋‹ค. Rate_Plan์€ Plan_ID(Unique Identifier), ๊ตฌ๋…์ œ์˜ ์ด๋ฆ„์ธ Plan Name, ๊ตฌ๋… ๊ฐ€๊ฒฉ์ธ Price, ๋งค๋‹ฌ ์ œ๊ณต๋˜๋Š” ์ฐจ์˜ ์ˆ˜๋Ÿ‰์ธ Provided Count ์ •๋ณด๋ฅผ ์ €์žฅํ•ด์•ผ ํ•œ๋‹ค. ๊ตฌ๋…์„ ํ•œ ํšŒ์›๋งŒ์ด ๊ตฌ๋…ํšŒ์› ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ €์žฅ์ด ๋˜๋Š” ๋ฐ˜๋ฉด, ๊ณ ๊ฐ์— ์˜ํ•ด ๊ตฌ๋…๋˜์–ด ์ง€์ง€ ์•Š์€ ๊ตฌ๋…์ œ๋”๋ผ๋„ ๋‚˜์ค‘์— ๋ˆ„๊ตฐ๊ฐ€์— ์˜ํ•ด ๊ตฌ๋…์ด ๋  ์ˆ˜ ์žˆ๊ธฐ์— ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ €์žฅ๋˜๋„๋ก ํ•ด์•ผํ•œ๋‹ค.

  2. A์‚ฌ๋Š” ๊ฐ๊ฐ์˜ ๊ณ ๊ฐ์— ์˜ํ•ด ๋ฐœ์ƒํ•œ ์ฃผ๋ฌธ(Order) ์ •๋ณด๋ฅผ ์ €์žฅํ•˜๊ธธ ์›ํ•œ๋‹ค. ์ฃผ๋ฌธ์—๋Š” Order ID(Unique Identifier)์™€ ์–ธ์ œ ์ฃผ๋ฌธ์ด ์ผ์–ด๋‚ฌ๋Š”์ง€์— ๋Œ€ํ•œ Order Date๊ฐ€ ์ €์žฅ๋œ๋‹ค. ๊ฐ๊ฐ์˜ ๊ณ ๊ฐ์€ ์—ฌ๋Ÿฌ๊ฐœ์˜ ์ฃผ๋ฌธ์„ ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ๊ฐ๊ฐ์˜ ์ฃผ๋ฌธ์€ ํ•œ๋ช…์˜ ๊ณ ๊ฐ์— ์˜ํ•ด ์ผ์–ด๋‚œ๋‹ค. ๊ณ ๊ฐ์— ์˜ํ•ด ๋ฐœ์ƒ ๋œ ์ฃผ๋ฌธ๋งŒ์ด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ €์žฅ๋˜์–ด์งˆ์ˆ˜ ์žˆ๋Š” ๋ฐ˜๋ฉด, ์ฃผ๋ฌธ์„ ํ•˜์ง€ ์•Š์€ ๊ณ ๊ฐ์ด๋ผ๋„ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ €์žฅ๋  ์ˆ˜ ์žˆ๋‹ค.

  3. A์‚ฌ๋Š” ๋ธ”๋ Œ๋”ฉ ํ‹ฐ(Blending Tea)์— ๋Œ€ํ•ด Tea ID, Name, Stock(์žฌ๊ณ ์ˆ˜๋Ÿ‰), Price(๊ฐ€๊ฒฉ)๋ฅผ ์ €์žฅํ•˜๊ธธ ์›ํ•˜๋ฉฐ, ๊ฐ๊ฐ์˜ ๋ธ”๋ Œ๋”ฉ ํ‹ฐ๋Š” ์—ฌ๋Ÿฌ ์ฃผ๋ฌธ(Order)์— ์ฃผ๋ฌธ(orderred)๋˜์–ด์งˆ์ˆ˜ ์žˆ๊ณ (๊ฐ๊ฐ์˜ ์ฃผ๋ฌธ์€ ์—ฌ๋Ÿฌ ๋ธ”๋ Œ๋”ฉ ํ‹ฐ๋ฅผ ์ฃผ๋ฌธ(orderred)ํ• ์ˆ˜ ์žˆ๋‹ค๋Š” ๋ง์˜ ์˜๋ฏธ๋Š” ๊ฐ๊ฐ์˜ ์ฃผ๋ฌธ ๋ฐ์ดํ„ฐ์—๋Š” ์—ฌ๋Ÿฌ ๋ธ”๋ Œ๋”ฉ ํ‹ฐ๋ฅผ ๋‹ด์„ ์ˆ˜ ์žˆ๋‹ค๋Š” ์˜๋ฏธ๋กœ ๋ณด๋Š”๊ฒƒ์ด ์ดํ•ด๊ฐ€ ์‰ฝ๋‹ค.) , ๊ฐ๊ฐ์˜ ์ฃผ๋ฌธ์€ ์—ฌ๋Ÿฌ ๋ธ”๋ Œ๋”ฉ ํ‹ฐ๋ฅผ ์ฃผ๋ฌธํ• ์ˆ˜ ์žˆ๋‹ค. Blending Tea๋ฅผ ์ฃผ๋ฌธํ•œ Order๋งŒ์ด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ €์žฅ๋˜๋Š” ๋ฐ˜๋ฉด, ์ฃผ๋ฌธ์ด ๋˜์–ด์ง€์ง€ ์•Š์€ Blending Tea์ผ์ง€๋ผ๋„ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ €์žฅ๋˜์–ด์งˆ ์ˆ˜ ์žˆ๋‹ค. ๋˜ํ•œ ๋ธ”๋ Œ๋”ฉ ํ‹ฐ๊ฐ€ ์ฃผ๋ฌธ ๋˜์–ด์งˆ๋•Œ, ์ฃผ๋ฌธ๋œ ์ˆ˜๋Ÿ‰(Quantity)๊ฐ€ ์ €์žฅ๋œ๋‹ค.

  4. ๋ธ”๋ Œ๋”ฉ ํ‹ฐ๋Š” ๊ธฐ๋ณธ์ด ๋˜์–ด์ง€๋Š” ์ฐจ์— ๋‹ค๋ฅธ์ฐจ๋‚˜ ์žฌ๋ฃŒ๋“ค์„ ์„ž์–ด ์ œ์ž‘์ด ๋˜์–ด์ง€๋Š”๋ฐ, A์‚ฌ๋Š” ์ด๋Ÿฌํ•œ ๊ธฐ๋ณธ์ด ๋˜์–ด์ง€๋Š” ์ฐจ๋‚˜ ์žฌ๋ฃŒ๋“ค์„ Material์— ์ €์žฅํ•˜๊ณ  ์‹ถ์–ดํ•œ๋‹ค. Material์—๋Š” ๋ธ”๋ Œ๋”ฉ ํ‹ฐ์™€ ๋น„์Šทํ•˜๊ฒŒ Material ID(Unique Identifier), Name, Stock, Price ์ •๋ณด๊ฐ€ ์ €์žฅ๋œ๋‹ค. ๊ฐ๊ฐ์˜ ๋ธ”๋ Œ๋”ฉ ํ‹ฐ๋Š” ์—ฌ๋Ÿฌ Material์„ ์ด์šฉํ•˜์—ฌ ์ œ์ž‘๋˜์–ด์ง€๊ณ , ๊ฐ๊ฐ์˜ Material ๋˜ํ•œ ์—ฌ๋Ÿฌ Blending Tea์˜ ์ œ์ž‘์— ์“ฐ์ผ ์ˆ˜ ์žˆ๋‹ค. ์•ž์„œ ๋งํ–ˆ๋“ฏ Blending Tea๋Š” ๊ธฐ์กด์— ์กด์žฌํ•˜๋Š” ์ฐจ์— ๋‹ค๋ฅธ ์ฐจ๋‚˜ ์žฌ๋ฃŒ๋“ค์„ ์ถ”๊ฐ€ํ•˜์—ฌ ๋งŒ๋“ค์–ด์ง„ ๊ฒƒ์ด๋ฏ€๋กœ ๋ฐ˜๋“œ์‹œ Material ์œผ๋กœ ์ œ์ž‘๋˜์–ด์•ผ ํ•˜๋Š” ๋ฐ˜๋ฉด, ์•„์ง Blending Tea์˜ ์ œ์ž‘์— ์“ฐ์ด์ง€ ์•Š์€ Material์ด๋ผ๋„ ๋‚˜์ค‘์— ์ƒˆ๋กœ์šด ์ข…๋ฅ˜์˜ Blending Tea์˜ ์ œ์ž‘ ๋“ฑ์— ์“ฐ์ผ ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์กด์žฌํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•œ๋‹ค. ์ถ”๊ฐ€์ ์œผ๋กœ, Material์ด Blending Tea์˜ ์ œ์ž‘์— ์ด์šฉ๋ ๋•Œ, ์–ผ๋งŒํผ์˜ ์–‘(Amount)์ด ๋“ค์–ด๊ฐ”๋Š”์ง€ ํ‘œ์‹œํ•œ๋‹ค. ์ฐธ๊ณ ) A์‚ฌ๋Š” Material์— ๋Œ€ํ•ด ๊ณต๊ธ‰์ž๊ฐ€ ์ œ์‹œํ•˜๋Š” ๊ฐ€๊ฒฉ์ด ์•„๋‹Œ A์‚ฌ๊ฐ€ ํฌ๋งํ•˜๋Š” ๊ฐ€๊ฒฉ์— ๋งž์ถฐ์ฃผ๋Š” ๊ณต๊ธ‰์ž๋“ค๋กœ๋ถ€ํ„ฐ ๊ณ„์•ฝ์„ ์ฒด๊ฒฐํ•˜์—ฌ Material์„ ๊ณต๊ธ‰๋ฐ›๊ณ  ์žˆ๋‹ค. ์ด๋Š” ์šฐ๋ฆฌ ํŒ€์ด ERD ์„ค๊ณ„์‹œ ์žฌ๋ฃŒ์˜ ๊ฐ€๊ฒฉ์— ๋Œ€ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ๋‹ด๊ณ ์žˆ๋Š” Price์• ํŠธ๋ฆฌ๋ทฐํŠธ๋ฅผ Material ๋ฆด๋ ˆ์ด์…˜ํƒ€์ž… ์ชฝ์— ์„ค์ •ํ•œ ์ด์œ ์ด๋‹ค.

  5. ๊ฐ๊ฐ์˜ Material์€ ๊ณต๊ธ‰์—…์ฒด(Supplier)์— ์˜ํ•ด ๊ณต๊ธ‰๋˜๋Š”๋ฐ, ๊ณต๊ธ‰์—…์ฒด๋Š” Supply ID(Unique Identifier), Name, Address(์‹œ/๋™/ํ˜ธ), PhoneNumber ์˜ ์ •๋ณด๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์œผ๋ฉฐ, ๊ฐ๊ฐ์˜ Supplier๋Š” ์—ฌ๋Ÿฌ Material์„ ๊ณต๊ธ‰ํ•  ์ˆ˜ ์žˆ๊ณ , ๊ฐ๊ฐ์˜ Material ๋˜ํ•œ ์—ฌ๋Ÿฌ Supplier์— ์˜ํ•ด ๊ณต๊ธ‰๋  ์ˆ˜ ์žˆ๋‹ค. ์•„์ง Supplier์— ์˜ํ•ด ๊ณต๊ธ‰๋œ ์ ์ด ์—†๋Š” Material๋„ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์กด์žฌํ•  ์ˆ˜ ์žˆ์ง€๋งŒ, Material์„ ํ•œ๋ฒˆ์ด๋ผ๋„ ๊ณต๊ธ‰ํ•œ ์ ์ด ์žˆ๋Š” Supplier๋งŒ์ด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ €์žฅ๋œ๋‹ค. ๊ณต๊ธ‰์ด ์ด๋ค„์งˆ๋•Œ ๋‚ ์งœ์™€ ๊ณต๊ธ‰์ˆ˜๋Ÿ‰์— ๋Œ€ํ•œ ์ •๋ณด๊ฐ€ ๊ธฐ๋ก๋œ๋‹ค. ๋ฉ”๋ชจ) Supplier์™€ Material์˜ Realtionship Type์— ๊ธฐ๋ก๋œ Date๋Š” ํ›„์— Relational Model๋กœ ๋ณ€ํ™˜ํ• ๋•Œ ์ƒˆ๋กœ ์ƒ์„ฑ๋  ๋ฆด๋ ˆ์ด์…˜์— ์ž„์˜์ ์œผ๋กœ Primary key์˜ ์ผ๋ถ€๋กœ ์„ค์ •ํ•˜์—ฌ Material ID + Supply ID + Date์˜ ํ˜•์‹์œผ๋กœ ๊ธฐ๋ณธํ‚ค๋ฅผ ์ด๋ฃจ๊ฒŒ ํ•˜์—ฌ ๊ฐ๊ฐ์˜ ๊ณต๊ธ‰์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ๊ธฐ๋กํ• ์ˆ˜ ์žˆ๋„๋ก ํ™œ์šฉํ•  ๊ณ„ํš์ด๋‹ค.

  6. Blending Tea๋Š” Blender์— ์˜ํ•ด ๋งŒ๋“ค์–ด์ง„๋‹ค. Blender์—๋Š” Blender ID(Unique Identifier), Name, Address(์‹œ/๋™/ํ˜ธ), PhoneNumber ๋ฅผ ์ €์žฅํ•œ๋‹ค. Blender ์ค‘์—๋Š” Blending Tea๋ฅผ ๋งŒ๋“ค๊ธฐ ์ „์— A์‚ฌ์™€ ๊ณ„์•ฝ์„ ํ•˜๋Š” ๊ฒฝ์šฐ๋„ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์•„์ง ๋งŒ๋“  Blending Tea๊ฐ€ ์—†๋Š” Blender๋„ ์ €์žฅ๋  ์ˆ˜ ์žˆ์ง€๋งŒ Blending Tea์˜ ๊ฒฝ์šฐ Blender๊ฐ€ ๋งŒ๋“œ๋Š” ๊ฒƒ์ด๊ธฐ์— ๋ฐ˜๋“œ์‹œ ํ•ด๋‹น ํ‹ฐ๋ฅผ ๋งŒ๋“  Blender๊ฐ€ ์กด์žฌํ•ด์•ผ๋งŒ ํ•œ๋‹ค. ์ด ๋•Œ, A์‚ฌ๋Š” Blender์—๊ฒŒ Blending Tea๋ฅผ ๋งŒ๋“ค์–ด์„œ ํŒ” ๋•Œ ๋งˆ๋‹ค Blender์—๊ฒŒ ์ผ์ •๋Ÿ‰์˜ Royalty๋ฅผ ์ง€๊ธ‰ํ•œ๋‹ค.

  7. ๊ฐ๊ฐ์˜ Blender๋Š” ์ž์‹ ์„ ๊ด€๋ฆฌํ•˜๋Š” Employee 1๋ช…์„ ๋ฐฐ์ •๋ฐ›์•„ ๊ด€๋ฆฌ๋œ๋‹ค. Employee์— ๋Œ€ํ•œ ์ •๋ณด๋Š” Employee ID(Unique Identifier), Name, Address(์‹œ/๋™/ํ˜ธ), PhoneNumber ๊ทธ๋ฆฌ๊ณ  Salary๊ฐ€ ํ•„์š”ํ•˜๋‹ค. Employee๋Š” ์—ฌ๋Ÿฌ๋ช…์˜ Blender๋ฅผ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค. ๋˜ํ•œ A์‚ฌ์—์„œ๋Š” ์‚ฌ์ˆ˜ - ๋ถ€์‚ฌ์ˆ˜๊ฐ„์˜ 1๋Œ€1 ์‚ฌ๋‚ด๊ต์œก์„ ์‹ค์‹œํ•˜๊ณ  ์žˆ๋‹ค. ๋ณดํ†ต ์‚ฌ์ˆ˜์™€ ๋ถ€์‚ฌ์ˆ˜์˜ ๊ฒฝ์šฐ ์ง์œ„๊ฐ€ ์‚ฌ์›๊ณผ ์ฃผ์ž„ ์ •๋„์ผ ํ™•๋ฅ ์ด ๋†’๊ณ , ์‚ฌ์ˆ˜๋‚˜ ๋ถ€์‚ฌ์ˆ˜๊ฐ€ ์—†๋Š” ๊ณ ์ฐธ ์ง์›๋“ค์ด๋‚˜, ๊ต์œก์ด ๋”ฑํžˆ ํ•„์š” ์—†๋Š” ๋ถ€์„œ์— ์†Œ์†๋œ ์ง์› ๋“ฑ์€ ์ด ์‚ฌ๋‚ด๊ต์œก์— ์ฐธ์—ฌํ•˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ๋‹ค๋Š” ๋น„์ฆˆ๋‹ˆ์Šค ๋ฃฐ์„ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ๋ฐ˜์˜ํ•ด์•ผ ํ•œ๋‹ค. ํšŒ์‚ฌ์—์„œ๋Š” ์‚ฌ๋‚ด๊ต์œก์ด ์ด๋ฃจ์–ด์งˆ ๋•Œ ์ด์— ๋Œ€ํ•œ ๊ฒฉ๋ ค์˜ ์˜๋ฏธ๋กœ ๊ต์œก๊ธฐ๊ฐ„์— ๋”ฐ๋ผ Incentive๋ฅผ ์ฐจ๋“ฑ์ง€๊ธ‰ํ•˜๋Š”๋ฐ ์ด๋ฅผ ์œ„ํ•ด ๊ฐ€๋ฅด์น˜๋Š” ๋‚ ์งœ์™€ ๋๋‚œ ๋‚ ์งœ๋ฅผ ๊ธฐ๋กํ•œ๋‹ค(Start Date, End Date).

  8. A์‚ฌ์—๋Š” ์—ฌ๋Ÿฌ๊ฐ€์ง€์˜ Department๊ฐ€ ์žˆ๊ณ  ์ด๋ฅผ ์ €์žฅํ•˜๋Š”๋ฐ ๊ฐ๊ฐ์˜ DepartmentID(Unique Identifier), Name, PhoneNumber, FAXNumber, Location์„ ์ €์žฅํ•œ๋‹ค. ๊ฐ๊ฐ์˜ Department์—๋Š” ์ตœ์†Œ ํ•œ๋ช…์—์„œ ์—ฌ๋Ÿฌ Employee๊ฐ€ ์†ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ๋ชจ๋“  Employee๋Š” ๋ฐ˜๋“œ์‹œ 1๊ฐœ์˜ ๋ถ€์„œ์—(๋งŒ) ์†ํ•ด์•ผ ํ•œ๋‹ค.

  9. A์‚ฌ๋Š” ์•„๋ž ๋ฌธํ™”๊ถŒ์— ๋Œ€ํ•œ ์ดํ•ด๋ฅผ ๋†’์ด๊ณ ์ž ์‚ฌ์›๋“ค์—๊ฒŒ ๋ฐ˜๋“œ์‹œ 1๊ฐœ์ด์ƒ์˜ Lecture๋ฅผ ๋“ค์„ ๊ฒƒ์„ ๊ทœ์น™์œผ๋กœ ๋‘๊ณ  ์žˆ๋‹ค. Lecture๋Š” Lecture ID(Unique Identifier), Name, TutorName, Time, Place์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•ด์•ผ ํ•˜๋ฉฐ, ๊ฐ๊ฐ์˜ Employee๋Š” ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๊ฐ•์˜๋ฅผ ๋“ค์„ ์ˆ˜ ์žˆ๊ณ  ๊ฐ๊ฐ์˜ ๊ฐ•์˜๋Š” ์—ฌ๋Ÿฌ๋ช…์ด ๋“ค์„ ์ˆ˜ ์žˆ๋‹ค. ๋˜ํ•œ ๊ทธ ๋ˆ„๊ตฌ์˜ Employee๋„ ์ˆ˜๊ฐ•ํ•˜์ง€ ์•Š์€ Lecture๋ผ๋„ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์กด์žฌํ•  ์ˆ˜ ์žˆ๋‹ค. ๊ฐ•์˜๋ฅผ ๋“ค์œผ๋ฉด Employee๊ฐ€ Lecture๋ฅผ ๋“ค์€ ๋‚ ์งœ์™€ Lecture๊ฐ€ ๋๋‚œ ์ดํ›„์— ํ€ด์ฆˆ๋ฅผ ์‹ค์‹œํ•˜์—ฌ ๊ทธ ์„ฑ์ ์„ ๊ธฐ๋กํ•œ๋‹ค.

4. Conceptual design (ERD)

image

5. Logical design (Relational schema)

Department(Department_ID, DepartmentName, DepartmentPhoneNum, FAXNumber, Location)
Employee(Employee_ID, EmployeeName, Si, Dong, Ho, PhoneNumber, Salary, Department_ID, Mentor_ID, StartDate, EndDate, Incentive)
FOREIGN KEY (Department_ID) REFERENCES Department(Department_ID)
FOREIGN KEY (Mentor_ID) REFERENCES Employee(Employee_ID)

Lecture(Lecture_ID, LectureName, TutorName, Time, Place)
Lecture_Taken(Employee_ID, Lecture_ID, Date, Grade)
FOREIGN KEY (Employee_ID) REFERENCES Employee(Employee_ID)
FOREIGN KEY (Lecture_ID) REFERENCES Lecture(Lecture_ID)

Blender(Blender_ID, Name, Age, Si, Dong, Ho, PhoneNumber, Gender, Employee_ID)
FOREIGN KEY (Employee_ID) REFERENCES Employee(Employee_ID)

BlendingTea(Tea_ID, Name, Stock, Price, Blender_ID, Royalty)
FOREIGN KEY (Blender_ID) REFERENCES Blender(Blender_ID)

Material(Material_ID, Name, Stock, Price)
BlendingTea_Manufactured(Tea_ID, Material_ID, Amount)
FOREIGN KEY (Tea_ID) REFERENCES BlendingTea (Tea_ID)
FOREIGN KEY (Material_ID) REFERENCES Material(Material_ID)

Supplier(Supplier_ID, Name, Si, Dong, Ho, PhoneNumber)
Material_Supplied(Material_ID, Supplier_ID, Quantity, Date)
FOREIGN KEY (Material_ID) REFERENCES Material(Material_ID)
FOREIGN KEY (Supplier_ID) REFERENCES Supplier(Supplier_ID)

Customer(Customer_ID, Name, Si, Dong, Ho, LoginID, LoginPassword, Gender, BirthDate)
Customer_PhoneNumber(Customer_ID, PhoneNumber)
FOREIGN KEY (Customer_ID) REFERENCES Customer(Customer_ID)

Regular(Customer_ID, Point)
FOREIGN KEY (Customer_ID) REFERENCES Customer(Customer_ID)

Rate_Plan(Plan_ID, PlanName, Price, ProvidedCount)
Subscriber(Customer_ID, CreditCardNumber, Plan_ID, SubscribeDate)
FOREIGN KEY (Customer_ID) REFERENCES Customer(Customer_ID)
FOREIGN KEY (Plan_ID) REFERENCES Rate_Plan(Plan_ID)

Order(Order_ID, OrderDate, Customer_ID)
FOREIGN KEY (Customer_ID) REFERENCES Customer(Customer_ID)

BlendingTea_Ordered(Tea_ID, Order_ID, Quantity)
FOREIGN KEY (Tea_ID) REFERENCES BlendingTea(Tea_ID)
FOREIGN KEY (Order_ID) REFERENCES Order(Order_ID)

  • ์ •๊ทœํ˜• Check
    Relation์˜ ๋ชจ๋“  Attribute๊ฐ€ Atomic ํ•˜๋ฏ€๋กœ : 1NF ์ถฉ์กฑ
    Every non-primary-key attribute is FULLY functionally dependent on the primary key ์ฆ‰, Partial Functional Dependecy ๊ฐ€ ์—†์œผ๋ฏ€๋กœ : 2NF ์ถฉ์กฑ
    Transitive Functional Dependency ๊ฐ€ ์—†์œผ๋ฏ€๋กœ : 3NF ์ถฉ์กฑ

6. Physical design & Data dictionary

์ด ๋‹จ๊ณ„์—์„œ Denormalization์€ ํ•˜์ง€ ์•Š๊ธฐ๋กœ ๊ฒฐ์ •. Data dictionary๋Š” Data Dictionary.pdf ํŒŒ์ผ ์ฐธ์กฐ

7. Creating tables & Insert data

Create&Insert.sql ํŒŒ์ผ ์ฐธ์กฐ

8. Useful SQL

1.์–ด๋–ค ๊ณ ๊ฐ์ด O0012 ์ฃผ๋ฌธ์„ ํ•œ๋‹ค๊ณ  ๊ฐ€์ •ํ•˜๋ฉด, ์•„๋ž˜์™€ ๊ฐ™์€ SQL์ด ๋™์ž‘ํ•˜์—ฌ ๋ธ”๋ Œ๋”ฉ ํ‹ฐ์˜ ์žฌ๊ณ  ์ƒํƒœ๊ฐ€ ๊ฐฑ์‹ ๋œ๋‹ค.

UPDATE 
(
SELECT stock,quantity
FROM blendingtea, blendingtea_ordered, ordertable
WHERE blendingtea.tea_id = blendingtea_ordered.tea_id 
AND blendingtea_ordered.order_id = ordertable.order_id
AND ordertable.order_id = 'O0012'
)
SET stock = stock - quantity;

์„ค๋ช… : O0012 ์ฃผ๋ฌธ์— ๋Œ€ํ•œ ์ฃผ๋ฌธ์ˆ˜๋Ÿ‰(quantity) ๋งŒํผ blending tea์˜ ์žฌ๊ณ (stock)๊ฐ€ ๋น ์ ธ์•ผ ํ•˜๋ฏ€๋กœ, ์กฐ์ธ์„ ํ†ตํ•ด ์–ด๋–ค ๋ธ”๋ Œ๋”ฉ ํ‹ฐ(tea_id)๊ฐ€ ์–ด๋–ค ์ฃผ๋ฌธ(order_id)์— ์‚ฌ์šฉ๋˜์—ˆ๋Š”์ง€ ์ •๋ณด๋ฅผ ํŒŒ์•…ํ•ด์•ผ ํ•œ๋‹ค. ๋”ฐ๋ผ์„œ ํ…Œ์ด๋ธ”๋“ค์„ ์œ„์™€ ๊ฐ™์ด ์กฐ์ธํ•ด์ฃผ๊ณ , blendingtea_orderred์˜ ์ฃผ๋ฌธ๋œ quantity๋งŒํผ blendingtea์˜ ์žฌ๊ณ ์ธ stock์„ ๋นผ์ฃผ๊ณ  ์ด๋ฅผ ๊ฐฑ์‹ ํ•ด์ฃผ๋ฉด ์žฌ๊ณ  ๊ฐฑ์‹ ์ด ๋˜๋Š”๊ฒƒ์ด๋‹ค. ํ•ด๋‹น SQL๋ฌธ์„ ์‹คํ–‰์‹œํ‚ค๋ฉด 200๊ฐœ์ด๋˜ T0014์˜ ์žฌ๊ณ ๊ฐ€ O0012์˜ ์ฃผ๋ฌธ์ˆ˜๋Ÿ‰์ธ 88๊ฐœ๋งŒํผ ๋น ์ ธ์„œ 112๊ฐœ๊ฐ€ ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

2.๊ณต๊ธ‰์—…์ฒด๊ฐ€ ์›์žฌ๋ฃŒ๋ฅผ ๊ณต๊ธ‰ํ• ๋•Œ ์•„๋ž˜์™€ ๊ฐ™์€ SQL์„ ํ†ตํ•ด ์žฌ๊ณ  ์ •๋ณด๋ฅผ ์—…๋ฐ์ดํŠธํ•œ๋‹ค. ๊ณต๊ธ‰์ž S0012๊ฐ€ ์›์žฌ๋ฃŒ M0005๋ฅผ ๊ณต๊ธ‰ํ•œ๋‹ค๊ณ  ๊ฐ€์ •ํ•˜๋ฉด, ์•„๋ž˜์™€ ๊ฐ™์€ SQL์ด ๋™์ž‘ํ•œ๋‹ค.

UPDATE 
(
SELECT stock, quantity
FROM material, material_supplied, supplier
WHERE material.material_id = material_supplied.material_id
AND material_supplied.supplier_id = supplier.supplier_id
AND supplier.supplier_id = 'S0012'
AND material.material_id = 'M0005'
)
SET stock = stock+quantity;

์„ค๋ช… : ๊ณต๊ธ‰์„ ๋ฐ›์œผ๋ฉด ๋ฐ›์€ ๋งŒํผ ์žฌ๊ณ ๊ฐ€ ๋Š˜์–ด๋‚˜์•ผ ํ•œ๋‹ค. ์œ„ SQL์˜ ์ƒํ™ฉ์—์„  S0012 id๋ฅผ ๊ฐ€์ง„ ๊ณต๊ธ‰์ž(Supplier)๋กœ๋ถ€ํ„ฐ M0005 id๋ฅผ ๊ฐ€์ง„ ์›์žฌ๋ฃŒ(Material)๋ฅผ ๊ณต๊ธ‰๋ฐ›๋Š” ์ƒํ™ฉ์„ ๊ฐ€์ •ํ•œ๋‹ค. ์žฌ๊ณ ๋ฅผ ๊ฐฑ์‹ ํ•˜๋ ค๋ฉด ์šฐ์„  ์กฐ์ธ์„ ํ†ตํ•ด ์–ด๋–ค ๊ณต๊ธ‰์ž(supplier_id)๊ฐ€ ์–ด๋–ค ์›์žฌ๋ฃŒ(material_id)๋ฅผ ๊ณต๊ธ‰ํ–ˆ๋Š”์ง€ ์ •๋ณด๋ฅผ ํŒŒ์•…ํ•ด์•ผ ํ•œ๋‹ค. ๋”ฐ๋ผ์„œ ์กฐ์ธ์„ ํ†ตํ•ด ์ด๋ฅผ ์ถ”์ ํ•˜์—ฌ material_supplied๋กœ ์—ฐ๊ฒฐํ•ด์ฃผ๊ณ , material_supplied์˜ quantity๋งŒํผ material์˜ stock์— ๋”ํ•ด์ฃผ๋ฉด ์›์žฌ๋ฃŒ์˜ ์žฌ๊ณ  ๊ฐฑ์‹ ์ด ์™„๋ฃŒ๋œ๋‹ค.

3. ๊ฐ€์žฅ ๊ฐ€์žฅ ๋งŽ์ด ํŒ๋งค๋œ ๋ธ”๋ Œ๋”ฉ ํ‹ฐ๋ฅผ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•˜์—ฌ ์•„๋ž˜์™€ ๊ฐ™์€ ์ฟผ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

SELECT tea_id, tea_name, sell 
FROM (SELECT tea_id, SUM(quantity) as sell from blendingtea_ordered GROUP BY tea_id) NATURAL JOIN blendingtea 
WHERE sell = (SELECT MAX(sell) FROM (SELECT tea_id,SUM(quantity) as sell from blendingtea_ordered GROUP BY tea_id));

์„ค๋ช…: ๊ฐ€์žฅ ์ž˜ ํŒ”๋ฆฌ๋Š” ์ฐจ์™€ ๊ทธ ์ฐจ์˜ ํŒ๋งค๋Ÿ‰์„ ์•Œ์•„๋ณด๊ธฐ ์œ„ํ•ด ํ˜„์žฌ ordertable์— ์˜ฌ๋ผ์˜จ ์ฃผ๋ฌธ์—์„œ ํŒ๋งค๋œ ์ฐจ๋ณ„๋กœ ํŒ๋งค๋œ ์–‘์˜ ํ•ฉ์„ ๊ตฌํ•˜๊ณ  ์ด ์ค‘ ํŒ๋งค๋Ÿ‰์ด ๊ฐ€์žฅ ํฐ ์ฐจ์˜ ID์™€ ์ด๋ฆ„, ํŒ๋งค๋Ÿ‰์„ ๋ถˆ๋Ÿฌ์˜จ๋‹ค.

4. ๊ฐ๊ฐ์˜ ๋ธ”๋žœ๋”๊ฐ€ ๋งŒ๋“  ๋ธ”๋žœ๋”ฉ ํ‹ฐ์˜ ๊ฐœ์ˆ˜/ํŒ๋งค๋Ÿ‰์˜ ํ•ฉ์„ ๋ณด์—ฌ์ฃผ๋Š” ๋ทฐ

CREATE OR REPLACE VIEW made
AS SELECT blender_id,
COUNT(*) as maded,
SUM(quantity) as sales_rate
FROM blendingtea, blendingtea_ordered
WHERE blendingtea.tea_id = blendingtea_ordered.tea_id GROUP BY blender_id;

์„ค๋ช…: ํšŒ์‚ฌ์— ์†ํ•ด์žˆ๋Š” ๋ธ”๋žœ๋”๊ฐ€ ๋ช‡๊ฐœ์˜ ๋ธ”๋žœ๋”ฉ ํ‹ฐ๋ฅผ ๋งŒ๋“ค์—ˆ๋Š”์ง€๋ฅผ ๋ณด์—ฌ์ฃผ๊ณ  ๊ฐ๊ฐ์˜ ๋งŒ๋“ค์–ด์ง„ ํ‹ฐ๋“ค์˜ ํŒ๋งค๋Ÿ‰์˜ ํ•ฉ์„ ๋‚˜ํƒ€๋‚ด๋Š” ๋ทฐ์ด๋‹ค, OR REPLACE ๋ฅผ ๋ช…์‹œํ•˜์˜€๊ธฐ ๋•Œ๋ฌธ์— ํŒ๋งค๋Ÿ‰์ด๋‚˜ ์ƒˆ๋กœ์šด ๋ธ”๋žœ๋”ฉ ํ‹ฐ๊ฐ€ ๊ฐœ๋ฐœ์ด ๋˜๋ฉด ํ•ด๋‹น ์ฟผ๋ฆฌ๋ฅผ ์‹คํ–‰์‹œํ‚ค๋ฉด ์—…๋ฐ์ดํŠธ๋„ ๊ฐ€๋Šฅํ•˜๋‹ค.

5. ๊ณ ๊ฐ์ด ์ž์‹ ์˜ ๊ตฌ๋งค ๋‚ด์—ญ์„ ํ™•์ธํ•˜๊ณ  ์‹ถ์„ ๊ฒฝ์šฐ ๊ณ ๊ฐ์—๊ฒŒ ์•„๋ž˜์˜ VIEW๋ฅผ ์ œ๊ณตํ•œ๋‹ค. View์—๋Š” ์ž์‹ ์ด ์–ธ์ œ ์–ด๋–ค ์ฃผ๋ฌธ์„ ํ–ˆ๊ณ , ๊ทธ ์ฃผ๋ฌธ์—์„œ ์–ด๋–ค ์ฐจ๋ฅผ, ๋ช‡๊ฐœ๋ฅผ ์‹œ์ผฐ๊ณ  ์ด ์–ผ๋งˆ๋ฅผ ๊ฒฐ์ œํ–ˆ๋Š”์ง€(๋ธ”๋ Œ๋”ฉ ํ‹ฐ์˜ ๊ฐœ๋‹น ๊ฐ€๊ฒฉ * ์ฃผ๋ฌธ ์ˆ˜๋Ÿ‰) ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค. - ์•„๋ž˜์˜ ์ƒํ™ฉ์€ C0001 ๊ณ ๊ฐ์ด ์ž์‹ ์˜ ๊ตฌ๋งค ๋‚ด์—ญ์„ ์กฐํšŒํ•˜๋Š” ์ƒํ™ฉ์ด๋‹ค.

CREATE OR REPLACE VIEW purchase_history
AS SELECT ordertable.order_id, order_date, blendingtea.tea_name, blendingtea_ordered.quantity, blendingtea_ordered.quantity * blendingtea.price as purchase_price
FROM ordertable,blendingtea_ordered,blendingtea
WHERE ordertable.order_id = blendingtea_ordered.order_id
AND blendingtea_ordered.tea_id = blendingtea.tea_id
AND ordertable.customer_id = 'C0001';

์„ค๋ช…: OR REPLACE VIEW๋กœ ๋งŒ๋“ค์–ด์„œ ๊ธฐ์กด์— ๊ฐ™์€ ์ด๋ฆ„์˜ VIEW๊ฐ€ ์žˆ๋”๋ผ๋„ ์ƒˆ๋กญ๊ฒŒ ๊ทธ๋•Œ ๊ทธ๋•Œ ๋ทฐ๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•˜์˜€๋‹ค(๊ทธ๋ƒฅ CREATE VIEW๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๊ธฐ์กด์— purchase_history ๋ทฐ๋ฅผ ์ƒ์„ฑํ–ˆ์„ ๊ฒฝ์šฐ ์ƒˆ๋กญ๊ฒŒ ๋ทฐ๋ฅผ ๊ฐฑ์‹ ํ•˜์ง€ ๋ชปํ•œ๋‹ค.) ํ•ด๋‹น ์ฃผ๋ฌธ์— ๋Œ€ํ•ด(ordertable.order_id) ์–ด๋–ค ๋ธ”๋ Œ๋”ฉ ํ‹ฐ๊ฐ€ ์ฃผ๋ฌธ๋˜์–ด์กŒ๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด blendingtea_ordered ํ…Œ์ด๋ธ”๊ณผ ์กฐ์ธํ•ด ์ฃผ์—ˆ๊ณ , ํ•ด๋‹น ๋ธ”๋ Œ๋”ฉ ํ‹ฐ์˜ ๊ฐœ๋‹น ๊ฐ€๊ฒฉ์„ ์•Œ์•„์•ผ ํ•˜๊ธฐ์— ๊ฐ€๊ฒฉ ์ •๋ณด๊ฐ€ ์ €์žฅ๋˜์–ด์ง„ blendingtea ํ…Œ์ด๋ธ”๊ณผ ์กฐ์ธํ•ด ์ฃผ์—ˆ๋‹ค.

  1. ๊ตฌ๋…์ž(Subscriber)์˜ ๊ฒฝ์šฐ ์•„๋ž˜์˜ SQL๊ณผ ๊ฐ™์ด ์ •๊ธฐ์ ์œผ๋กœ ordertable๊ณผ blendingtea_ordered ์— ์ƒˆ๋กœ์šด ์ฃผ๋ฌธ์ด rate_plan์— ๋ช…์‹œ๋œ ๊ฐœ์ˆ˜์™€ ๊ณ ๊ฐ์ด ์„ ํƒํ•œ ์ฐจ๋กœ insert ์‹œ์ผœ์ค€๋‹ค.
INSERT INTO ordertable (order_id,order_date,customer_id) select 'O0019', subscribe_date,customer_id from subscriber NATURAL JOIN rate_plan where customer_id='C0012' ;

INSERT INTO blendingtea_ordered (tea_id,order_id,quantity) select 'T0009', order_id,provided_amount from subscriber NATURAL JOIN rate_plan natural join ordertable where order_id='O0019';

์„ค๋ช…: rate_plan ํ…Œ์ด๋ธ”์˜ provied amount๋Š” ํ•ด๋‹น ๊ตฌ๋…์ œ๋ฅผ ๊ฒฐ์ œํ–ˆ์„ ๋•Œ ๋‹ฌ๋งˆ๋‹ค ๋ช‡๊ฐœ์˜ ์ฐจ๊ฐ€ ๊ณ ๊ฐ์—๊ฒŒ ๋ฐฐ์†ก๋˜๋Š”์ง€์˜ ์–‘์ด๋‹ค. ๋งŒ์ผ ๊ตฌ๋…์ œ๋กœ ํ•ด๋‹น ๊ธฐ์—…์˜ ์„œ๋น„์Šค๋ฅผ ์ด์šฉํ•˜๋Š” C0012 ๊ณ ๊ฐ์ด ์ฐจ ID๊ฐ€ T0009์ธ ์ƒํ’ˆ์„ ์ •๊ธฐ์ ์œผ๋กœ ๋ฐ›๊ธฐ๋กœ ์„ ํƒํ–ˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•˜๋ฉด ๊ณ ๊ฐ์ด ๊ตฌ๋…ํ•œ ๊ตฌ๋…์ œ์—์„œ ์ œ๊ณต๋˜๋Š” provided amount ๋งŒํผ ํ•ด๋‹น ์ฐจ๊ฐ€ ํ•œ๋‹ฌ์— ํ•œ๋ฒˆ์”ฉ ๊ณ ๊ฐ์—๊ฒŒ ๋ฐฐ์†ก๋  ๊ฒƒ์ด๋‹ค. ์ด๋Š” provided amount ๋งŒํผ์˜ ์ฐจ ์ฃผ๋ฌธ์ด ordertable์— ๋“ค์–ด๊ฐ€๋Š” ๊ฒƒ๊ณผ ๊ฐ™๊ธฐ์— ์œ„์™€ ๊ฐ™์€ SQL์ด ํ•„์š”ํ•œ ๊ฒƒ์ด๋‹ค. subscriber๊ฐ€ ์ •๊ธฐ ๊ตฌ๋…์ด ๋งค๋‹ฌ ์—…๋ฐ์ดํŠธ๊ฐ€ ๋  ๋•Œ ๋งˆ๋‹ค order table๊ณผ blendingtea_ordered ํ…Œ์ด๋ธ”์— ์ƒˆ๋กœ์šด ์ฃผ๋ฌธ์„ ๋„ฃ์–ด์„œ ๊ธฐ๋ก์— ๋‚จ๊ธด๋‹ค. ์œ„ ์ฟผ๋ฆฌ๋Š” C0012 ๊ณ ๊ฐ์ด ์—…๋ฐ์ดํŠธ๊ฐ€ ๋˜์—ˆ์„ ๋•Œ ๋งˆ์ง€๋ง‰ ์ฃผ๋ฌธ์ธ O0018๋’ค์— O0019์„ ์ถ”๊ฐ€ ํ•˜๋ฉด์„œ blendingtea_ordered ์—๋„ ๊ณ ๊ฐ์ด ์ง€์ •ํ•œ T0009๊ฐ€ ํ•ด๋‹น rate_plan์— ์ ํ˜€์žˆ๋Š” provided amount๋งŒํผ ์ฃผ๋ฌธ๊ธฐ๋ก์ด ์ž๋™์œผ๋กœ ์ถ”๊ฐ€๋œ๋‹ค. ์ฆ‰, ์ด ๊ณ ๊ฐ์˜ ๊ฒฝ์šฐ ๋งค๋‹ฌ 30๊ฐœ์˜ ์ฐจ๊ฐ€ ์ œ๊ณต๋˜๋Š” Basic Plan์„ ์ฑ„ํƒํ•œ ๊ณ ๊ฐ์ด๊ธฐ์— 30๊ฐœ์˜ ์ˆ˜๋Ÿ‰๋งŒํผ order๊ฐ€ ๋ฐœ์ฃผ๋˜๋Š” ๊ฒƒ์ด๋‹ค.

  1. ๋ธ”๋ Œ๋”์˜ ์—ฐ๋ น๋Œ€(ํ‰๊ท )๋ณ„ ๋ฐ›๋Š” ๋กœ์—ดํ‹ฐ๋ฅผ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ๋‚˜ํƒ€๋‚ธ๋‹ค.
SELECT royalty, AVG(blender.age) as Average_age 
FROM blender, blendingtea 
WHERE blender.blender_id = blendingtea.blender_id 
GROUP BY royalty 
ORDER BY AVG(blender.age);



  1. ๋ธ”๋ Œ๋”์˜ ๋‚˜์ด๊ฐ€ 30์ดํ•˜์™€ ์„ฑ๋ณ„์— ๋”ฐ๋ผ ๊ฐœ๋ฐœ๋˜๋Š” ์ฐจ์˜ ์ด๋ฆ„์„ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ๋‚˜ํƒ€๋‚ธ๋‹ค. ์ฐจ๋ฅผ ๊ฐœ๋ฐœํ•˜๋Š” ์‚ฌ๋žŒ์˜ ๋‚˜์ด์™€ ์„ฑ๋ณ„์— ๋”ฐ๋ผ ์–ด๋–ค ์ข…๋ฅ˜์˜ ํ‹ฐ๋ฅผ ๋งŒ๋“œ๋Š”์ง€ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ๋‹ค.
SELECT age,gender, tea_name 
FROM blender, blendingtea 
WHERE blender.blender_id = blendingtea.blender_id and age<30 
GROUP BY age, gender, tea_name 
ORDER BY tea_name; 



  1. ๊ณ ๊ฐ์ด ๊ตฌ๋…ํ•  ์š”๊ธˆ์ œ์˜ ์ด๋ฆ„, ๊ฐ€๊ฒฉ, ์ œ๊ณต๋˜๋Š” ์ฐจ์˜ ๊ฐœ์ˆ˜๋ฅผ ๋น„์‹ผ ๊ฐ€๊ฒฉ์ˆœ์œผ๋กœ ๋ณด์—ฌ์ค€๋‹ค.
SELECT plan_name, price, provided_amount 
FROM rate_plan 
ORDER BY price DESC;



  1. A๋ฅผ ๋งŽ์ด ๋ฐ›์€ ์ง์› ์ˆœ์œผ๋กœ ์ •๋ ฌํ•˜์—ฌ ์šฐ์ˆ˜ ์ง์›์„ ์‹œ์ƒํ•˜๊ธฐ ์œ„ํ•ด ์•„๋ž˜์™€ ๊ฐ™์ด ๊ฐ•์˜๋ฅผ ์ˆ˜๊ฐ•ํ•œ ์ง์› ์ค‘ ์„ฑ์  A๋ฅผ ๋ฐ›์€ ์ง์›์˜ ์ด๋ฆ„, ์ „ํ™”๋ฒˆํ˜ธ, A๋ฅผ ๋ฐ›์€ ํšŸ์ˆ˜๋ฅผ ๋ณด์—ฌ์ค€๋‹ค.
SELECT emp_name,phone_number, count(emp_id) as grade_A 
FROM lecture_taken NATURAL JOIN employee 
WHERE grade = 'A'
group by emp_id,emp_name,phone_number
order by grade_A DESC;



  1. ํ•ด๋‹น ๊ธฐ์—…์€ ์ตœ๊ทผ ๊ตฌ๋…ํ•œ ๊ณ ๊ฐ๋“ค์—๊ฒŒ ์ด๋ฒคํŠธ๋ฅผ ์ค€๋น„์ค‘์— ์žˆ๊ธฐ์— 2022๋…„ 12์›” ์ดํ›„๋กœ ๊ตฌ๋…ํ•œ ๊ตฌ๋…์ž์˜ ์ด๋ฆ„, ์ฃผ์†Œ(์‹œ,๋™,ํ˜ธ), ๋กœ๊ทธ์ธ ID, ๊ตฌ๋…์ผ์„ ์•„๋ž˜์˜ SQL๋ฌธ์„ ํ†ตํ•ด ํŒŒ์•…ํ•œ๋‹ค.. ์ตœ๊ทผ์— ๊ตฌ๋…ํ•œ ์‚ฌ๋žŒ ์ˆœ์œผ๋กœ ์ •๋ ฌํ•ด์„œ ๊ตฌ๋… ๊ฐฑ์‹ ํ•œ ์‚ฌ๋žŒ์„ ๊ตฌ๋ถ„ํ•œ๋‹ค.
SELECT customer_name,si,dong,ho,login_id,subscribe_date
FROM customer NATURAL JOIN subscriber 
WHERE subscribe_date > '2022-11-30' 
ORDER BY subscribe_date DESC;



  1. 90๋…„๋Œ€ ์ถœ์ƒํ•œ ๊ณ ๊ฐ์ค‘ ์„ฑ๋ณ„ ๊ธฐ์ค€์œผ๋กœ ๊ณ ๊ฐ์„ ๋‚˜๋ˆ„์–ด ์ˆ˜๋ฅผ ์„ผ๋‹ค. ์„œ๋น„์Šค๋ฅผ ์ด์šฉํ•˜๋Š” ๊ณ ๊ฐ์ด ์ฒญ๋…„์ธต์ด ์–ผ๋งˆ๋‚˜ ์ด์šฉํ•˜๋Š”์ง€, ์–ด๋–ค ์„ฑ๋ณ„์ด ์ฃผ๋กœ ์ด์šฉํ•˜๋Š”์ง€ ํŒŒ์•…ํ•˜๋Š”๋ฐ ์‚ฌ์šฉํ•œ๋‹ค.
SELECT gender,count(customer_id) as gender_count 
FROM customer 
WHERE birthdate > '1989-12-31' AND birthdate < '2000-01-01' 
GROUP BY gender;



  1. ๊ณ ๊ฐ์ด๋‚˜ ์ง์›, ๋ธ”๋žœ๋”๊ฐ€ ์ด์‚ฌํ•  ๋•Œ ์•„๋ž˜์™€ ๊ฐ™์€ UPDATE ๋ฌธ์œผ๋กœ ์ฃผ์†Œ๋ฅผ ์—…๋ฐ์ดํŠธ ํ•  ์ˆ˜ ์žˆ๋‹ค.
UPDATE customer 
SET si = '๋ถ€์ฒœ', dong = '์†ก๋‚ด๋™', ho ='13'
WHERE customer_id = 'C0003';

Geonwoo Kim's Projects

course-material icon course-material

Course Material for in28minutes courses on Java, Spring Boot, DevOps, AWS, Google Cloud, and Azure.

wedy icon wedy

Weather-based clothing and music recommendation applications

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.