출처 : 네이버 지식iN


case연산자의 사용법은

case 비교컬럼 when 비교값 then 변환값 when 비교값 then 변환값........else default값 end

ex) select case a when 0 then 'yes' when 1 then 'no' else 'zzz' end from table
=>위와 똑같은 결과.....
이것도 when과 then을 잘 써서 순서를 맞추구요...else뒤에값이 default값입니다...


사용예..
select case when b02 = 0 then b01
when b03 = 0 then b02
when b04 = 0 then b03
when b05 = 0 then b04
.......
when b85 = 0 then b84
end
from test2

참고하세요^^


------ 이런것도 될까? -_-;; --------------------
SELECT if(col='RED',RED,'') as red, if(col='BLUE',BLUE,'') as blue, if(col='WHITE',WHITE,'') as white, FROM COLOR;
----------------------------------------------
profile