본문 바로가기
Web Programing!/POSTGRESQL

[POSTGRESQL] order by 정렬순서 내마음대로 바꾸기 (CASE WHEN 사용)

by 어설픈봉봉이 2019. 9. 24.
반응형
SMALL




[POSTGRESQL] order by 정렬순서 내마음대로 바꾸기 (CASE WHEN 사용)

1. 일반적으로 order by 를 했을시

select * from 테이블명 order by 필드명 asc;

2. CASE WHEN 사용하여 내가 원하는 정렬순서로 변경시

select

*

from 테이블명

order by

case

when 필드명 ='ko' then 0

when 필드명 ='en' then 1

end;

3. CASE WHEN 사용하여 내가 원하는 정렬순서로 변경하고 나머지는 원래 정렬순서대로 정렬

select

*

from 테이블명

order by

case

when 필드명 ='ko' then 0

when 필드명 ='en' then 1

end

, 필드명 asc;







반응형