[PostgreSQL] order by 정렬 순서를 내 마음대로 하는 방법

gayoung·2024년 2월 19일

DB

목록 보기
14/16

내가 원하는 순서대로 order by를 하는 경우 CASE WHEN을 사용하면 된다.

select * from table_A ta
order by case when ta.class_name = '진반' then 0
			  when ta.class_name = '선반' then 1
			  when ta.class_name = '미반' then 2
			  when ta.class_name = '혜반' then 3 end
	   , ta.stu_name 

0개의 댓글