WITH T
AS (
SELECT 'KKK' AS ID, 10 POINT, '005' AS GRP1, '2012' AS GB FROM DUAL
UNION ALL
SELECT 'KKK' AS ID, 30 POINT, '003' AS GRP1, '2013' AS GB FROM DUAL
UNION ALL
SELECT 'KKK' AS ID, 20 POINT, '001' AS GRP1, '2013' AS GB FROM DUAL
UNION ALL
SELECT 'KKK' AS ID, 15 POINT, '007' AS GRP1, '2014' AS GB FROM DUAL
UNION ALL
SELECT 'KKK' AS ID, 40 POINT, '007' AS GRP1, '2014' AS GB FROM DUAL
)
SELECT ID,
DECODE(GB, '2012', GRP1) AS GRP12,
DECODE(GB, '2012', POINT) AS POINT12,
DECODE(GB, '2013', GRP1) AS GRP13,
DECODE(GB, '2013', POINT)AS POINT13,
DECODE(GB, '2014', GRP1)AS GRP14,
DECODE(GB, '2014', POINT)AS POINT14
FROM T;
이렇게 하면 중간에 공백이 생깁니다. 숫자같으면 SUM을 쓰고 문자를 하나만 보여주면 MIN이나 MAX를 사용하면되는데
이건 모든 열을 다보여줘야되서..
공백을 없을수 있는 방법이 있을까요???
쿼릴 돌려보시면 현재 5개로우인데
로우가 2개만 나오면 되거든요..
오라클 11의 PIVOT기능을 사용하지 않고 DECODE등으로 할방법이 있을까요?
|