Growth ๐ŸŒณ/Practice ๐Ÿ’ป

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ๊ฒฝ๊ธฐ๋„์— ์œ„์น˜ํ•œ ์‹ํ’ˆ์ฐฝ๊ณ  ๋ชฉ๋ก ์ถœ๋ ฅํ•˜๊ธฐ

์ธ” 2022. 10. 23. 22:54

๐Ÿ“ข ๋ณธ ํฌ์ŠคํŒ…์— ํ™œ์šฉ๋˜๋Š” ๊ธฐ๋ณธ ๋ฌธ์ œ ๋ฐ ์ž๋ฃŒ ์ถœ์ฒ˜๋Š”

       ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต,   
      https://school.programmers.co.kr/learn/challenges?page=1&languages=mysql%2Coracle
์ž„์„ ๋ฐํž™๋‹ˆ๋‹ค.


โ–  ๋ฌธ์ œ

https://school.programmers.co.kr/learn/courses/30/lessons/131114

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.

programmers.co.kr

 

๋ฌธ์ œ ์„ค๋ช…

 

๋‹ค์Œ์€ ์‹ํ’ˆ์ฐฝ๊ณ ์˜ ์ •๋ณด๋ฅผ ๋‹ด์€ FOOD_WAREHOUSE ํ…Œ์ด๋ธ”์ž…๋‹ˆ๋‹ค. 

FOOD_WAREHOUSE ํ…Œ์ด๋ธ”์€ ๋‹ค์Œ๊ณผ ๊ฐ™์œผ๋ฉฐ WAREHOUSE_ID, WAREHOUSE_NAME, ADDRESS, TLNO, FREEZER_YN๋Š” ์ฐฝ๊ณ  ID, ์ฐฝ๊ณ  ์ด๋ฆ„, ์ฐฝ๊ณ  ์ฃผ์†Œ, ์ „ํ™”๋ฒˆํ˜ธ, ๋ƒ‰๋™์‹œ์„ค ์—ฌ๋ถ€๋ฅผ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.

WAREHOUSE_ID VARCHAR(10) FALSE
WAREHOUSE_NAME VARCHAR(20) FALSE
ADDRESS VARCHAR(100) TRUE
TLNO VARCHAR(20) TRUE
FREEZER_YN VARCHAR(1) TRUE

 


๋ฌธ์ œ

FOOD_WAREHOUSE ํ…Œ์ด๋ธ”์—์„œ ๊ฒฝ๊ธฐ๋„์— ์œ„์น˜ํ•œ ์ฐฝ๊ณ ์˜ ID, ์ด๋ฆ„, ์ฃผ์†Œ, ๋ƒ‰๋™์‹œ์„ค ์—ฌ๋ถ€๋ฅผ ์กฐํšŒํ•˜๋Š” SQL๋ฌธ์„ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”. ์ด๋•Œ ๋ƒ‰๋™์‹œ์„ค ์—ฌ๋ถ€๊ฐ€ NULL์ธ ๊ฒฝ์šฐ, 'N'์œผ๋กœ ์ถœ๋ ฅ์‹œ์ผœ ์ฃผ์‹œ๊ณ  ๊ฒฐ๊ณผ๋Š” ์ฐฝ๊ณ  ID๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌํ•ด์ฃผ์„ธ์š”.


โ–  ํ’€์ด

  ๋ฌธ์ œ ์š”๊ตฌ์‚ฌํ•ญ  

๊ฒฝ๊ธฐ๋„์— ์œ„์น˜ํ•œ                                                        > WHERE์ ˆ์— ADDRESS์ปฌ๋Ÿผ '๊ฒฝ๊ธฐ๋„' ํฌํ•จ ์กฐ๊ฑด ์ถ”๊ฐ€

๋ƒ‰๋™์‹œ์„ค ์—ฌ๋ถ€๊ฐ€ NULL์ธ ๊ฒฝ์šฐ 'N'์œผ๋กœ ์ถœ๋ ฅ      > SELECT ์ ˆ์— CASE WHEN ๋˜๋Š” IF๋ฌธ ํ™œ์šฉํ•ด์„œ ๋ƒ‰๋™์‹œ์„ค ์—ฌ๋ถ€ NULL
                                                                                         'N'์œผ๋กœ ๋Œ€์ฒด

๊ฒฐ๊ณผ๋Š” ์ฐฝ๊ณ  ID๊ธฐ์ค€ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ                        > ORDER BY์ ˆ์— ์ฐฝ๊ณ  ID ๊ธฐ์ค€ ์ •๋ ฌ

 

SELECT WAREHOUSE_ID,
WAREHOUSE_NAME,
ADDRESS,
CASE WHEN FREEZER_YN IS NULL THEN 'N' ELSE FREEZER_YN END FREEZER_YN
 FROM FOOD_WAREHOUSE
 WHERE ADDRESS LIKE '๊ฒฝ๊ธฐ๋„%'
 ORDER BY WAREHOUSE_ID;