제가 원하는결과 값은( M_WITHDR - M_DEPOSIT = 미수금) 해서 나온
이 미수금 값을 누적 하고자합니다.
도움을 주세요
한필드의 값을 누적하는 방법은 게시판 검색하니 나와있더군요.
self join으로 시도 했는데 잘안되더라구요.
원본 데이터
NUMBER__CODE__NAME______DATE_______DEPOSIT______WITHDR
__1________05____삼천수산___2003-01-28________________4,500,000
__2________05____삼천수산___2003-01-28__5,000,000_____________
__3________08____삼우수산___2003-01-31_______________11,070,000
__4________08____삼우수산___2003-01-31____750,000______________
__5________04____해마수산___2003-02-03________________6,298,700
__6________04____해마수산___2003-02-03____750,000______________
__7________06____청수활어___2003-02-03________________2,740,000
__8________06____청수활어___2003-02-03____800,000______________
__9________08____삼우수산___2003-02-03________________6,600,000
__10_______08____삼우수산___2003-02-03____100,000______________
__11_______03____해송수산___2003-02-03_______________10,000,000
__12_______03____해송수산___2003-02-03____500,000______________
누적된 미수금이 첨가된 query결과
NUMBER__CODE__NAME____DATE_____DEPOSIT____WITHDR____미수금
__3________08__삼우수산__2003-01-31_____________11,070,000__11,070,000
__4________08__삼우수산__2003-01-31___750,000_______________10,320,000
__9________08__삼우수산__2003-02-03______________6,600,000__16,920,000
__10_______08__삼우수산__2003-02-03___100,000_______________16,820,000
select number, name, deposit, withdr ,
(select
(select sum(withdr) from cumulation a where a.number <= b.number ) - sum(deposit)
fromcumulation a where a.number <= b.number )
from cumulation b
테스트결과(삼우수산만 입력했습니당)
1 삼우수산 0 11070000 11070000
2 삼우수산 750000 0 10320000
3 삼우수산 0 6600000 16920000
4 삼우수산 100000 0 16820000
즐푸하세여..