๐Ÿ’ซ ๋ฌธ์ œ



 

๐Ÿ’ซ CODE

SELECT PT_NAME, PT_NO, GEND_CD, AGE, COALESCE(TLNO, 'NONE') AS TLNO
FROM PATIENT
WHERE AGE <= 12 AND GEND_CD = 'W'
ORDER BY AGE DESC, PT_NAME;

 

๐Ÿ’ซ ํ’€์ด ์กฐ๊ฑด

1. 12์„ธ ์ดํ•˜์ธ ์—ฌ์žํ™˜์ž
2. ํ™˜์ž์ด๋ฆ„(PT_NAME), ํ™˜์ž๋ฒˆํ˜ธ(PT_NO), ์„ฑ๋ณ„์ฝ”๋“œ(GEND_CD), ๋‚˜์ด(AGE), ์ „ํ™”๋ฒˆํ˜ธ(TLNO) ์กฐํšŒ
3. ์ „ํ™”๋ฒˆํ˜ธ(TLNO)๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ, 'NONE'์œผ๋กœ ์ถœ๋ ฅ
4. ๋‚˜์ด ๊ธฐ์ค€ ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌ, ๋‚˜์ด๊ฐ€ ๊ฐ™๋‹ค๋ฉด ํ™˜์ž์ด๋ฆ„ ๊ธฐ์ค€ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ

 

๐Ÿ’ซ ํ’€์ด

1. SELECT PT_NAME, PT_NO, GEND_CD, AGE, IFNULL(TLNO, 'NONE') AS TLNO
  • ํ™˜์ž์ด๋ฆ„(PT_NAME), ํ™˜์ž๋ฒˆํ˜ธ(PT_NO), ์„ฑ๋ณ„์ฝ”๋“œ(GEND_CD), ๋‚˜์ด(AGE), ์ „ํ™”๋ฒˆํ˜ธ(TLNO) ์กฐํšŒ
  • IFNULL(TLNO, 'NONE') ์ „ํ™”๋ฒˆํ˜ธ(TLNO)๊ฐ€ NULL ์ด๋ฉด 'NONE'์ด ์ถœ๋ ฅ๋˜๋„๋ก
2. WHERE AGE <= 12 AND GEND_CD = 'W'
  • ๋‚˜์ด(AGE)๊ฐ€ 12์ดํ•˜, ์„ฑ๋ณ„์ฝ”๋“œ(GEND_CD)๊ฐ€ 'W'์ธ ๊ฒฝ์šฐ
3. ORDER BY AGE DESC, PT_NAME
  • ๋‚˜์ด(AGE) ๊ธฐ์ค€ ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌ, ๋‚˜์ด(AGE)๊ฐ€ ๊ฐ™๋‹ค๋ฉด ํ™˜์ž์ด๋ฆ„(PT_NAME) ๊ธฐ์ค€ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ

By Dozzing

๋‹ต๊ธ€ ๋‚จ๊ธฐ๊ธฐ

์ด๋ฉ”์ผ ์ฃผ์†Œ๋Š” ๊ณต๊ฐœ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ํ•„์ˆ˜ ํ•„๋“œ๋Š” *๋กœ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค