[SQL] 문자열대체, null값 대체

도리·2025년 2월 14일

programmers lv1.12세 이하인 여자 환자 목록 출력하기

null값도 replace하면 되는줄 알았던 건에 대하여..,,

틀린 코드

SELECT pt_name, pt_no, gend_cd, replace(tlno, 'NULL', 'none') as age_tlno
from patient
where age <= 12
order by age desc, pt_name

띠용.
그냥 안나와버림

정답 코드


SELECT pt_name, pt_no, gend_cd, age,ifnull(tlno, 'NONE') as age_tlno
from patient
where age <= 12 and gend_cd = 'w'
order by age desc, pt_name
  • 틀린코드보면 age랑 gender조건도 안써놨더라 ,,

결론!

null_ 인 경우 -> ifnull
문자열 대체할 경우 -> replace

profile
인공지능응용학과 졸업예정..

0개의 댓글