WITH t AS (
SELECT 'E000001732695' AS ITEM_ID, '1772' AS PROMO_ID, '820' AS AMT FROM DUAL
UNION ALL
SELECT 'E000001732921' AS ITEM_ID, '1772' AS PROMO_ID, '13200' AS AMT FROM DUAL
UNION ALL
SELECT 'E000005174450' AS ITEM_ID, '1772' AS PROMO_ID, '5' AS AMT FROM DUAL
UNION ALL
SELECT 'E000001732923' AS ITEM_ID, '1772' AS PROMO_ID, '1310' AS AMT FROM DUAL
UNION ALL
SELECT 'E000001732930' AS ITEM_ID, '1773' AS PROMO_ID, '1500' AS AMT FROM DUAL
UNION ALL
SELECT 'E000001732959' AS ITEM_ID, '1773' AS PROMO_ID, '6000' AS AMT FROM DUAL
UNION ALL
SELECT 'E000001732940' AS ITEM_ID, '1773' AS PROMO_ID, '10000' AS AMT FROM DUAL
UNION ALL
SELECT 'E000001732980' AS ITEM_ID, '1774' AS PROMO_ID, '800' AS AMT FROM DUAL
UNION ALL
SELECT 'E000001732910' AS ITEM_ID, '1774' AS PROMO_ID, '900' AS AMT FROM DUAL )
SELECT * FROM t
위테이블에서 결과가
ITEM_ID PROMO_ID AMT
E000001732921 1772 13200
E000001732940 1773 6000
E000001732910 1774 900
PROMO_ID 별로 가장큰 AMT를 구하는 겁니다.
일단은
SELECT * FROM (
SELECT ITEM_ID, PROMO_ID, AMT
,ROW_NUMBER() OVER (PARTITION BY PROMO_ID ORDER BY AMT DESC ) RNUM
FROM t
)
WHERE RNUM = 1
이렇게 처리 했는데.. 보기도 않좋고 해서요
혹시 다른 좋은 방법 있으시면 가르켜 주세요.
게다가 파티션 바이 특성상.. 오라클에서 밖에 못쓸거 같고. : (