Q.

풀이 1
- coalesce(tlno, ‘NONE’)
- tlno가 null일 경우 “NONE” 반환하고 null이 아닐 경우 원래 tlno 값 반환
- order by age desc, pt_name asc
- age 기준 내림차순 정렬
- pt_name 기준 오름차순 정렬
select pt_name, pt_no, gend_cd, age, coalesce(tlno, 'NONE') as tlno
from patient
where age <= 12 and gend_cd = 'W'
order by age desc, pt_name asc;풀이 2
- case when tlno is null then 'NONE' else tlno end
- tlno가 null일 경우 “NONE”을 반환하고 null이 아닐 경우 원래 tlno 값 반환
- case when 조건 then 반환값 else 기본값 end(case문 종료)
select pt_name, pt_no, gend_cd, age,
case when tlno is null then 'NONE'
else tlno end as tlno
from patient
where age <= 12 and gend_cd = 'W'
order by age desc, pt_name asc;Share article