이렇게 하면 되지 않을까요?
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'))