티스토리 뷰

with temp as(

 select '1'  idx , '10' dept , '20170703' as lastm ,'기타' as data_etc from dual union all

 select '2'  idx , '20' dept , '20170704' as lastm ,'정상' as data_etc from dual union all

 select '2'  idx , '20' dept , '20170705' as lastm ,'비정상' as data_etc from dual union all

 select '3'  idx , '40' dept , '20170703' as lastm ,'기타' as data_etc from dual union all

 select '3'  idx , '40' dept , '20170701' as lastm ,'기타' as data_etc from dual union all

 select '4'  idx , '60' dept , '20170703' as lastm ,'기타' as data_etc from dual union all

 select '4'  idx , '60' dept , '20170702' as lastm ,'기타' as data_etc from dual 

)

select *

from (

        select a.*

             , row_number() over( partition by idx, dept order by lastm desc) rnk

        from temp a

     )   

where rnk = 1

order by idx 



'DEV > DB' 카테고리의 다른 글

ibatis remapResults  (0) 2016.10.28
index 리빌드  (0) 2015.11.26
PrepareStatment(#)와 Statment($)  (0) 2015.11.26
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함