case when 조건1 then 조건만족시 값1
when 조건2 then 조건만족시 값2
when 조건3 then 조건만족시 값3
...
else 값
end 결과칼럼명
질문) 이름과 주소를 확인하십시오. (단, 주소를 한글로 변경 후 다시 검색)
select uname, addr, case when addr="Seoul" then '서울'
when addr="Jeju" then '제주'
when addr="Busan" then '부산'
when addr="Suwon" then '수원'
end as juso
from sungjuk;

질문) 이름, 한국어 점수 및 GPA를 검색합니다.
학점: 한국어 90점 이상 “레벨 A”
80점 이상의 “B등급”
70점 이상의 “C등급”
60점 이상 ‘D등급’
나머지 “F 등급”
select uname, kor, case when kor>=90 then 'A학점'
when kor>=80 then 'B학점'
when kor>=70 then 'C학점'
when kor>=60 then 'D학점'
else 'F학점'
end as grade
from sungjuk;

A와 B 연산자 사이에 +) 사용
select uname, kor, case when kor between 90 and 100 then 'A학점'
when kor between 80 and 89 then 'B학점'
when kor between 70 and 79 then 'C학점'
when kor between 60 and 69 then 'D학점'
else 'F학점'
end as 국어학점
from sungjuk;
