๐ŸŒผํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค SQL ๊ณ ๋“์  Kit [IS NULL]

์œค๊ฑดํฌ(Guny)ยท2020๋…„ 10์›” 15์ผ
0

Database

๋ชฉ๋ก ๋ณด๊ธฐ
5/7
post-thumbnail

SQL ๊ณ ๋“์  Kit - IS NULL

๐Ÿ“š๊ฐ’์ด ์—†์Œ์„ ์˜๋ฏธํ•˜๋Š” NULL. NULL์„ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋ฐฐ์›Œ๋ด…์‹œ๋‹ค.


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

๋™๋ฌผ ๋ณดํ˜ธ์†Œ์— ๋“ค์–ด์˜จ ๋™๋ฌผ ์ค‘, ์ด๋ฆ„์ด ์—†๋Š” ์ฑ„๋กœ ๋“ค์–ด์˜จ ๋™๋ฌผ์˜ ID๋ฅผ ์กฐํšŒํ•˜๋Š” SQL ๋ฌธ์„ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”. ๋‹จ, ID๋Š” ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

SELECT ANIMAL_ID
FROM ANIMAL_INS
WHERE NAME IS NULL


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

๋™๋ฌผ ๋ณดํ˜ธ์†Œ์— ๋“ค์–ด์˜จ ๋™๋ฌผ ์ค‘, ์ด๋ฆ„์ด ์žˆ๋Š” ๋™๋ฌผ์˜ ID๋ฅผ ์กฐํšŒํ•˜๋Š” SQL ๋ฌธ์„ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”. ๋‹จ, ID๋Š” ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

SELECT ANIMAL_ID
FROM ANIMAL_INS
WHERE NAME IS NOT NULL


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

์ž…์–‘ ๊ฒŒ์‹œํŒ์— ๋™๋ฌผ ์ •๋ณด๋ฅผ ๊ฒŒ์‹œํ•˜๋ ค ํ•ฉ๋‹ˆ๋‹ค. ๋™๋ฌผ์˜ ์ƒ๋ฌผ ์ข…, ์ด๋ฆ„, ์„ฑ๋ณ„ ๋ฐ ์ค‘์„ฑํ™” ์—ฌ๋ถ€๋ฅผ ์•„์ด๋”” ์ˆœ์œผ๋กœ ์กฐํšŒํ•˜๋Š” SQL๋ฌธ์„ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”. ์ด๋•Œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์„ ๋ชจ๋ฅด๋Š” ์‚ฌ๋žŒ๋“ค์€ NULL์ด๋ผ๋Š” ๊ธฐํ˜ธ๋ฅผ ๋ชจ๋ฅด๊ธฐ ๋•Œ๋ฌธ์—, ์ด๋ฆ„์ด ์—†๋Š” ๋™๋ฌผ์˜ ์ด๋ฆ„์€ "No name" ์œผ๋กœ ํ‘œ์‹œํ•ด ์ฃผ์„ธ์š”.

SELECT ANIMAL_TYPE, IFNULL(NAME, "No name") AS NAME, SEX_UPON_INTAKE
FROM ANIMAL_INS
ORDER BY ANIMAL_ID

profile
๊ฐœ๋ฐœ์ž

0๊ฐœ์˜ ๋Œ“๊ธ€