# MySQL에서 Column의 값이 Null인 경우를 처리해주는 함수들은 IFNULL, IF & IS NULL, CASE와 같은 함수들이 있다
# 테이블 예시
select *
from country_student

# ifnull
[ 형식 ]
select ifnull( 컬럼명, null일 경우 대체값 )
from 테이블명
[ 예시 ]
select id, name, age, country,
ifnull(job, "잡이 없어용 ㅠㅠ") as job
from country_student
[ 결과 ]

# if 와 컬럼 is null
[ 예시 ]
select id, name, age, country,
if(job is null, "잡이 없어용 ㅠㅠ", job) as job
from country_student
[ 결과 ]

# case문
[ 예시 ]
select id, name, age, country,
case when job is null then "잡이 없서용 ㅠㅠ"
else job end as job
from country_student
[ 결과 ]

'Knowledge🦢 > SQL' 카테고리의 다른 글
| [SQL] Challenge 1회차 - 윈도우함수는 컬럼생성, first_value, last_value, lag, lead (1) | 2024.05.29 |
|---|---|
| [SQL] 윈도우함수 총정리 (0) | 2024.05.29 |
| [SQL] group by를 사용하는 이유 - group by, having✔️ (2) | 2024.05.15 |
| [SQL] with 문을 사용하여 가상의 테이블을 만들어 사용하기 (0) | 2024.05.14 |
| [SQL] SQL문제를 풀 때 중요하다고 생각하는 것들 (0) | 2024.05.13 |