ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

728x90
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

 

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

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

programmers.co.kr

 

๋ฌธ์ œ ํ’€์ด

 ํ•„๋“œ์˜ ๊ฐ’์ด `Null`์ธ ๊ฒฝ์šฐ, `WHERE` ๋˜๋Š” `IF`๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ `Null`์— ๋Œ€ํ•œ ์ฒ˜๋ฆฌ๋ฅผ ํ•˜๋ฉด ํ•„์š”์— ๋”ฐ๋ผ ๋ฐ˜์˜ ์—ฌ๋ถ€๋ฅผ ๊ฒฐ์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

์ฝ”๋“œ

์ด๋ฆ„์ด ์—†๋Š” ๋™๋ฌผ์˜ ์•„์ด๋””

SELECT ANIMAL_ID
FROM ANIMAL_INS
WHERE NAME IS NULL

 

์ด๋ฆ„์ด ์žˆ๋Š” ๋™๋ฌผ์˜ ์•„์ด๋””

SELECT ANIMAL_ID
FROM ANIMAL_INS
WHERE NAME IS NOT NULL
ORDER BY ANIMAL_ID

 

NULL ์ฒ˜๋ฆฌํ•˜๊ธฐ

SELECT
    ANIMAL_TYPE,
    IF (NAME IS NULL, 'No name', NAME) AS NAME,
    SEX_UPON_INTAKE
FROM ANIMAL_INS
ORDER BY ANIMAL_ID

 

728x90
๋ฐ˜์‘ํ˜•
๋Œ“๊ธ€
๊ธ€ ๋ณด๊ด€ํ•จ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€