안녕하세요.
이번에도 쿼리 좀 도와 주세요.
PIVOT 사용하면 될거 같은데 잘안되요..ㅠ
여기서 항상 많은 도움 받고 있는데 쿼리가 제일 어려운거 같아요..ㅠ
초기값
SELECT 'T' FLAG, '100' AS CD, 'A' AS CD2, 400 AS VAL1, 200 VAL2 FROM DUAL UNION ALL
SELECT 'T' FLAG, '100' AS CD, 'B' AS CD2, 400 AS VAL1, 200 VAL2 FROM DUAL UNION ALL
SELECT 'T' FLAG, '100' AS CD, 'C' AS CD2, 400 AS VAL1, 200 VAL2 FROM DUAL UNION ALL
SELECT 'T' FLAG, '200' AS CD, 'A' AS CD2, 500 AS VAL1, 200 VAL2 FROM DUAL UNION ALL
SELECT 'T' FLAG, '200' AS CD, 'B' AS CD2, 500 AS VAL1, 200 VAL2 FROM DUAL UNION ALL
SELECT 'T' FLAG, '200' AS CD, 'C' AS CD2, 500 AS VAL1, 200 VAL2 FROM DUAL UNION ALL
SELECT 'T' FLAG, '300' AS CD, 'A' AS CD2, 660 AS VAL1, 300 VAL2 FROM DUAL UNION ALL
SELECT 'T' FLAG, '300' AS CD, 'B' AS CD2, 660 AS VAL1, 300 VAL2 FROM DUAL UNION ALL
SELECT 'T' FLAG, '300' AS CD, 'C' AS CD2, 660 AS VAL1, 300 VAL2 FROM DUAL UNION ALL
SELECT 'F' FLAG, '100' AS CD, 'A' AS CD2, 400 AS VAL1, 200 VAL2 FROM DUAL UNION ALL
SELECT 'F' FLAG, '100' AS CD, 'B' AS CD2, 400 AS VAL1, 200 VAL2 FROM DUAL UNION ALL
SELECT 'F' FLAG, '100' AS CD, 'C' AS CD2, 400 AS VAL1, 200 VAL2 FROM DUAL UNION ALL
SELECT 'F' FLAG, '200' AS CD, 'A' AS CD2, 500 AS VAL1, 200 VAL2 FROM DUAL UNION ALL
SELECT 'F' FLAG, '200' AS CD, 'B' AS CD2, 500 AS VAL1, 200 VAL2 FROM DUAL UNION ALL
SELECT 'F' FLAG, '200' AS CD, 'C' AS CD2, 500 AS VAL1, 200 VAL2 FROM DUAL UNION ALL
SELECT 'F' FLAG, '300' AS CD, 'A' AS CD2, 660 AS VAL1, 300 VAL2 FROM DUAL UNION ALL
SELECT 'F' FLAG, '300' AS CD, 'B' AS CD2, 660 AS VAL1, 300 VAL2 FROM DUAL UNION ALL
SELECT 'F' FLAG, '300' AS CD, 'C' AS CD2, 660 AS VAL1, 300 VAL2 FROM DUAL
결과값
CD |
FLAG1 |
DIV |
A |
B |
C |
FLAG1 |
DIV |
A |
B |
C |
100 |
T |
VAL1 |
400 |
400 |
400 |
F |
VAL1 |
400 |
400 |
400 |
200 |
T |
VAL1 |
500 |
500 |
500 |
F |
VAL1 |
500 |
500 |
500 |
300 |
T |
VAL1 |
660 |
660 |
660 |
F |
VAL1 |
660 |
660 |
660 |
100 |
T |
VAL2 |
200 |
200 |
300 |
F |
VAL2 |
200 |
200 |
300 |
200 |
T |
VAL2 |
200 |
200 |
300 |
F |
VAL2 |
200 |
200 |
300 |
300 |
T |
VAL2 |
300 |
300 |
300 |
F |
VAL2 |
300 |
300 |
300 |
|