날짜 출고개수
-------------- ----------
2005010200 2
2005010300 1
2005030200 6
2006040200 4
2006110200 2
2006110700 2
2007040200 4
2007111200 1
2007112200 2
2008010200 2
2008010300 1
2008030200 9
위와 같은 데이터를 가진 테이블이 있을때 다음과 같은 쿼리를 써서 년도별 합계를 구했는데요...
select substr(a.out_tm,1,4) as 기준년도, sum(a.out_cnt) as 출고합계
from data_table a
where
a.out_tm between '2005010100' AND '2008123123'
group by substr(a.out_tm,1,4) order by substr(a.out_tm,1,4) asc;
기준년도 출고합계
--------- -----------
2005 9
2006 8
2007 7
2008 12
출고 합계 다음에 전년대비 증감수도 같이 나타 내고 싶습니다. 도움 부탁 드려요
기준년도 출고합계 증감수
--------- ---------- ------------
2005 9 -
2006 8 -1
2007 7 -1
2008 12 5 |