본문 바로가기

프로그래밍/oracle

oracle - 원하는 순서대로 출력(order by + case)

반응형

select * 

from 

(

SELECT BBS_DIV, COUNT(*) SEARCH_CNT

FROM T_BBS A

WHERE '^^' = '^^'

AND BBS_DIV IN ('QNA', 'FAQ', 'GON', 'FST')

AND STATUS = 'ACT'

AND (SUBJCT LIKE '%%' OR CONT LIKE '%%')

GROUP BY BBS_DIV


UNION


SELECT BBS_DIV, COUNT(*) SEARCH_CNT

FROM T_BBS A

WHERE '^^' = '^^'

AND BBS_DIV IN ('EVT')

AND STATUS = 'ACT'

AND (SUBJCT LIKE '%%' OR DBMS_LOB.INSTR(CONT_CLOB, '')>0 )

GROUP BY BBS_DIV


UNION


SELECT SRC_TABLE AS BBS_DIV, COUNT(*) SEARCH_CNT

FROM T_SEARCH_INDEX A

WHERE '^^' = '^^'

AND (TITLE  LIKE '%%' OR DBMS_LOB.INSTR(CONTENT,   '')>0 )

GROUP BY SRC_TABLE

)


order by (case

when bbs_div = 'EVT' then 2

when bbs_div = 'FAQ' then 4

when bbs_div = 'FST' then 3

when bbs_div = 'GON' then 5

when bbs_div = 'QNA' then 6

when bbs_div = 'T_BOARD_01' then 1

end ) ASC


반응형