쿼리_MSSQL
MS-SQL Case 함수 사용, inner join 사용
잠수콩
2008. 11. 18. 13:21
Case 함수 사용하기
select 이름, 직업 =
case b.job_code
when '1' then '회사원'
when '2' then '공무원'
when '3' then '학생'
when '4' then '백수'
when '5' then '기타'
else b.job_code
end
from JOB테이블 a inner join 회원테이블 b on a.job_code=b.job_code
where b.job_code is not null
order by a.regdate
직업테이블이 있고
회원테이블이 있을때
회원테이블에 job_code를 직업테이블에 있는 거들만 뽑아서 쓸때.
뭐 좀 이상하지만, 2개 테이블 조인해서 사용하여, Case로 직업뽑아내는것.