본문 바로가기
2019/ORACLE

SQL CASE-WHEN-THEN

by SOLYI 2019. 11. 15.

--case when 일때 then 이거로 바꿔라
select deptno, case deptno when 10 then 'a'
when 20 then 'b'
when 30 then 'c'
end as result from emp;

--case when 일때 then 이걸로 바꿔 else 나머지는이거
select deptno, case deptno when 10 then 'a'
when 20 then 'b'
else 'c'
end as result from emp;

--when condtion(조건)
select deptno, case 
when deptno=10 then 'a'
when deptno=20 then 'b'
else 'c' end
as result from emp;

--case 사용하여 직급에 따른 급여인상
select empno, ename, job, sal, deptno, case job
when 'ANALYST' then sal*1.05
when 'SALESMAN' then sal*1.1
when 'MANAGER' then sal*1.15
when 'CLERK' then sal*1.2 else sal
end as upsal from emp;

select empno, ename, job, sal, deptno, case 
when job='ANALYST' then sal*1.05
when job='SALESMAN' then sal*1.1
when job='MANAGER' then sal*1.15
when job='CLERK' then sal*1.2 else sal
end as upsal from emp;
반응형

'2019 > ORACLE' 카테고리의 다른 글

SQL group by having  (0) 2019.11.18
SQL sum avg count max min  (0) 2019.11.18
SQL DECODE  (0) 2019.11.15
SQL NVL NVL2  (0) 2019.11.15
SQL DATE  (0) 2019.11.15