[답변]품목, 작년상반기 수량합, 이번년반기 수량합을 조회하려합니다. 0 1 1,068

by 김하진 [2007.07.19 12:22:48]


이렇게 하면 되지 않을까요?

 

select item, qty2006, qty2007, qty2006-qty2007 수량차이

from  (select item,

               sum(decode(substr(date,1,4), '2006',qty) qty2006 ,

               sum(decode(substr(date,1,4), '2007',qty) qty2007 

         from invoice

         where date between '20060101'and '20070630'

         group by item

          )

 

지금은 인덱스를 사용하려고 불필요하게 2006년 7~12월 데이터까지 읽습니다만,

다음과 같이 변경해도 되겠죠.

 

where (date like '2006%' and substr(date,5,2)) in ('01','02','03','04','05','06')

or date like '2007%' and substr(date,5,2)) in ('01','02','03','04','05','06'))

by 오지현 [2007.07.19 00:00:00]
와아~ 감사감사 공부좀 많이해야할듯.. ㅠㅠ 감사합니다.
댓글등록
SQL문을 포맷에 맞게(깔끔하게) 등록하려면 code() 버튼을 클릭하여 작성 하시면 됩니다.
로그인 사용자만 댓글을 작성 할 수 있습니다. 로그인, 회원가입