반응형
case
간단한 조건문을 작성할때 사용하는 case( )
released_year가 2000년 이후에 나온 책들은 modern 이라고 하고,
그렇지 않은 책들은 Old 라고 새로운 컬럼을 만들어서 가져오세요
select *,
case
when released_year >= 2000 then 'Modern'
else 'Old'
end as 'Genre'
from books;

stock_quantity 가 0~50 사이면 *(별표 한개)
stock_quantity 가 51~100 사이면 **(별표 두개)
stock_quantity 가 그 외에는 ***(별표 세개)
select *,
case
when stock_quantity between 0 and 50 then '*'
when stock_quantity between 51 and 100 then '**'
else '***'
end as star
from books;

반응형
'TOOL > MySQL' 카테고리의 다른 글
| MySQL - 여러 테이블 생성 시 foreign key 설정하는 방법 (0) | 2022.05.17 |
|---|---|
| MySQL - if( ) (0) | 2022.05.17 |
| MySQL - date, time, datetime, timestamp (0) | 2022.05.16 |
| MySQL - max, min, avg, sum 함수 사용법 (0) | 2022.05.16 |
| MySQL - count , group by (0) | 2022.05.16 |