728x90
#case
case 식은 경우에 따라 값을 구분할 수 있습니다.
사용 방법
case when [조건식1] then [식1]
when [조건식2] then [식2]
when [조건식3] then [식3]
···
else [식n]
end
else는 위에서 만족하는 조건이 없을때의 반환값입니다.
생략할 수 있지만 명시적으로 작성하는것이 바람직합니다.
사용 예시
select col_1, col_2,
case when col_2 >= 6000 then 'high'
when col_2 >= 3000 and col_2 < 6000 then 'middle'
when col_2 < 3000 then 'low'
else null
end as col2_classify
from nameoftable;
'파이썬으로 퀀트 프로그램 만들기 project > MySQL' 카테고리의 다른 글
MySQL - 윈도우 함수 (0) | 2023.08.20 |
---|---|
MySQL - 테이블 결합, inner join, outer join (0) | 2023.07.31 |
MySQL - like 술어, 문자열 일치, between 술어, isnull, in 술어 (0) | 2023.07.31 |
MySQL - 날짜함수, extract (0) | 2023.07.31 |
MySQL - error code: 1175, safe update 모드 해제 방법 (0) | 2023.07.27 |