books 테이블

case로 시작 end로 끝나며 when을 통해 조건문과 then을 통해 원하는 값을 넣어준다.

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

 

+ Recent posts