컬럼의 누적합 구하기도 쿼리로 가능한가요? 0 2 2,445

by 세븐블랙홀 [2011.04.01 13:48:48]



with test_table as (select 'a000' as item_code ,'수요' as data_type ,40  as date_01 ,10  as date_02 ,83  as date_03 from dual union all
    select 'a000' as item_code ,'공급' as data_type ,10  as date_01 ,50  as date_02 ,20  as date_03 from dual union all
    select 'a001' as item_code ,'수요' as data_type ,30  as date_01 ,11  as date_02 ,67  as date_03 from dual union all
    select 'a001' as item_code ,'공급' as data_type ,88  as date_01 ,19  as date_02 ,91  as date_03 from dual union all
    select 'a002' as item_code ,'수요' as data_type ,73  as date_01 ,29  as date_02 ,46  as date_03 from dual union all
    select 'a002' as item_code ,'공급' as data_type ,51  as date_01 ,15  as date_02 ,33  as date_03 from dual
    )
select item_code
  ,data_type
  ,date_01
  ,date_02
  ,date_03
  from test_table
 
위와 같은 data가 있습니다..
여기서 item_code 별로 Row를 하나씩 추가 하고 싶은데요
그 data는
data_type = '과부족수량'
date_01 = date_01(공급Row) - date_01(수요Row)
date_02 = date_02(공급Row) - date_02(수요Row) + date_01(과부족수량 Row --위컬럼 합계)
date_03 = date_03(공급Row) - date_03(수요Row) + date_02(과부족수량 Row --위컬럼 합계)

이런식으로 컬럼이 90개가 있습니다.
이건 진정 procedure로 해결할수 밖에 없는건가요?
by camela [2011.04.01 14:18:19]
select item_code
,data_type
,date_01
,date_02
,date_03
from test_table
model
partition by (item_code)
dimension by (data_type)
measures (date_01, date_02, date_03)
rules(
date_01['과부'] = date_01['공급'] - date_01['수요']
,date_02['과부'] = date_02['공급'] - date_02['수요'] + date_01['과부']
,date_03['과부'] = date_03['공급'] - date_03['수요'] + date_02['과부']
)

by 세븐블랙홀 [2011.04.04 17:38:54]
우앗... 제가 너무 늦게 봤네요..
model 이네요.. 공부 중이였는데 감사 합니다..
medel이 공부하는데 어려운거 같아요.. ㅜ.ㅜ
댓글등록
SQL문을 포맷에 맞게(깔끔하게) 등록하려면 code() 버튼을 클릭하여 작성 하시면 됩니다.
로그인 사용자만 댓글을 작성 할 수 있습니다. 로그인, 회원가입