아직 model에 대해서 잘 이해가 아되서 한번 변경시켜 볼까 햇는데 잘 안되네요 ;;;
WITH T AS (
SELECT '2007' AS YEAR, 1000 AS AMT FROM DUAL UNION ALL
SELECT '2007' AS YEAR, 1100 AS AMT FROM DUAL UNION ALL
SELECT '2007' AS YEAR, 1200 AS AMT FROM DUAL UNION ALL
SELECT '2008' AS YEAR, 1000 AS AMT FROM DUAL UNION ALL
SELECT '2008' AS YEAR, 1200 AS AMT FROM DUAL UNION ALL
SELECT '2008' AS YEAR, 1400 AS AMT FROM DUAL UNION ALL
SELECT '2008' AS YEAR, 1600 AS AMT FROM DUAL UNION ALL
SELECT '2009' AS YEAR, 2000 AS AMT FROM DUAL UNION ALL
SELECT '2009' AS YEAR, 2200 AS AMT FROM DUAL UNION ALL
SELECT '2009' AS YEAR, 2400 AS AMT FROM DUAL UNION ALL
SELECT '2009' AS YEAR, 2600 AS AMT FROM DUAL UNION ALL
SELECT '2009' AS YEAR, 2500 AS AMT FROM DUAL
)
SELECT YEAR, tt, a, b, no
FROM ( select year, amt
, row_number() over( partition by year order by rownum ) as rn
from t
)
MODEL PARTITION BY ( year )
DIMENSION BY ( RN tt )
MEASURES( amt a, rn b, 0 no )
RULES(
no[any] = CASE WHEN max(a)[cv(tt)] = b[cv()] then sum(a)[cv()] else 0 end
)
order by 1,2
가장 큰값을 만나면 sum() 하면 될 느낌인데;;; 잘 안되네요 ㅠㅠ
조언좀 부탁드리겠습니다.