[MySQL] 4. SQL - IS NULL

sorzzzzyΒ·2021λ…„ 8μ›” 13일
1

MySQL

λͺ©λ‘ 보기
4/8
post-thumbnail

🏷 IS NULL

IS NULL μ—°μ‚°μžλŠ” 데이터 값이 null인 경우λ₯Ό μ‘°νšŒν•˜κ³ μž ν•  λ•Œ μ‚¬μš©ν•œλ‹€.
πŸ’‘ null은 0μ΄λ‚˜ 곡백(space)κ³ΌλŠ” μ—„μ—°νžˆ 닀름! 0은 숫자 값이고 곡백은 문자 κ°’μ΄λ―€λ‘œ λ‹€λ₯Έ μœ ν˜•μ˜ 데이터 값이닀!

SELECT "ν•„λ“œλͺ…"
FROM "ν…Œμ΄λΈ”λͺ…"
WHERE "ν•„λ“œλͺ…" IS NULL

SELECT "ν•„λ“œλͺ…"
FROM "ν…Œμ΄λΈ”λͺ…"
WHERE "ν•„λ“œλͺ…" IS NOT NULL

🏷 ν”„λ‘œκ·Έλž˜λ¨ΈμŠ€(SQL-Kit IS NULL)문제 풀이


1. 이름이 μ—†λŠ” λ™λ¬Όμ˜ 아이디

SELECT ANIMAL_ID
FROM ANIMAL_INS
WHERE NAME IS NULL
ORDER BY ANIMAL_ID

2. 이름이 μžˆλŠ” λ™λ¬Όμ˜ 아이디

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

3. NULL μ²˜λ¦¬ν•˜κΈ°

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

IFNULL을 μ‚¬μš©ν•΄ NULLμΌλ•Œλ₯Ό μ²˜λ¦¬ν•΄μ€€λ‹€


profile
Backend Developer

0개의 λŒ“κΈ€