누계를 구하고자 합니다 그냥 sum 으로 Query를 실행 하니 다 동일 한 값이 나옵니다.
현재 Table 값
code dat n_remark dr_amt cr_amt id
1022 전기이월 10000 00000000
1022 201401 월 계 10000 20140101
1022 201402 월 계 10000 20140201
보고자 하는 값
code dat n_remark dr_amt cr_amt id
1022 전기이월 10000 00000000
1022 201401 월 계 10000 20140101
1022 201401 누 계 20,000 20140102
1022 201402 월 계 10000 20140201
1022 201402 누 계 30000 20140202
Comment 3
-
Hisory
2014.09.25 13:43
-
항해자™
2014.09.25 16:52
mssql 2000 이라고 표기되어 있네요ㅎㅎ
-
건우아빠
2014.09.25 14:40
select *into #resfrom (select '1022' code , '' dat , '전기이월' n_remark ,10000 dr_amt ,'00000000' id union allselect '1022' code , '201401' dat , '월 계' n_remark ,10000 dr_amt ,'20140101' union allselect '1022' code , '201402' dat , '월 계' n_remark ,10000 dr_amt ,'20140201' ) rselect a.code ,a.dat ,a.dr_amt ,a.id , b.*from #res a join #res b on a.id >= b.idorder by a.code ,a.dat ,a.dr_amt ,a.id-----------------------------------------------------select *from(select * , 1 sort_gbfrom #resunion allselect a.code ,a.dat , '누 계 ' n_remark , SUM( a.dr_amt) dr_amt ,a.id , 2 sort_gbfrom #res a join #res b on a.id >= b.idgroup by a.code ,a.dat ,a.idhaving a.dat <> '') rorder by code, dat , sort_gb
rollup 을 써보시는건 어떨까여