카테고리 없음

select 문 중간에 case

sdafdq 2023. 11. 6. 10:46
select m.mem_id, m.mem_name, sum(price * amount) "총 구매액",
	case
		when sum(price * amount) >= 1500 then '최우수 고객'
		when sum(price * amount) >= 1000 then '우수 고객'
		when sum(price * amount) >= 1 then '일반 고객'
        else '유령 고객'
	end '회원등급'
 from buy b right join member m on b.mem_id = m.mem_id group by mem_id order by sum(price * amount) desc;