안녕하세요.
row을 컬럼으로 변경하는 쿼리 좀 봐주세요,
이리 저리 해보는데 잘 안되네요.ㅠ
SELECT '홍길동' AS name, '국어' AS subject, 77 AS score_1, 88 AS score_2 FROM dual UNION ALL
SELECT '홍길동' AS name, '영어' AS subject, 86 AS score_1, 85 AS score_2 FROM dual UNION ALL
SELECT '홍길동' AS name, '수학' AS subject, 70 AS score_1, 65 AS score_2 FROM dual UNION ALL
SELECT '강호동' AS name, '국어' AS subject, 90 AS score_1, 98 AS score_2 FROM dual UNION ALL
SELECT '강호동' AS name, '영어' AS subject, 92 AS score_1, 87 AS score_2 FROM dual UNION ALL
SELECT '강호동' AS name, '수학' AS subject, 64 AS score_1, 71 AS score_2 FROM dual UNION ALL
SELECT '전지현' AS name, '국어' AS subject, 100 AS score_1, 98 AS score_2 FROM dual UNION ALL
SELECT '전지현' AS name, '수학' AS subject, 96 AS score_1, 100 AS score_2 FROM dual UNION ALL
SELECT '이영애' AS name, '국어' AS subject, 96 AS score_1, 98 AS score_2 FROM dual UNION ALL
SELECT '이영애' AS name, '영어' AS subject, 99 AS score_1, 100 AS score_2 FROM dual UNION ALL
SELECT '이영애' AS name, '수학' AS subject, 100 AS score_1, 100 AS score_2 FROM dual
이름 |
과목 |
score_1 |
score_2 |
홍길동 |
국어 |
77 |
88 |
홍길동 |
영어 |
86 |
85 |
홍길동 |
수학 |
70 |
65 |
강호동 |
국어 |
90 |
98 |
강호동 |
영어 |
92 |
87 |
강호동 |
수학 |
64 |
71 |
전지현 |
국어 |
100 |
98 |
전지현 |
수학 |
96 |
100 |
이영애 |
국어 |
96 |
98 |
이영애 |
영어 |
99 |
100 |
이영애 |
수학 |
100 |
100 |
아래처럼 나오게 하고 싶어요.
참 과목은 늘어 날수도 있어요.
|
전체합계 |
국어 |
영어 |
수학 |
|
score_1 |
score_2 |
합계 |
score_1 |
score_2 |
합계 |
score_1 |
score_2 |
합계 |
score_1 |
score_2 |
합계 |
홍길동 |
233 |
238 |
471 |
77 |
88 |
165 |
86 |
85 |
171 |
70 |
65 |
135 |
강호동 |
246 |
256 |
502 |
90 |
98 |
188 |
92 |
87 |
179 |
64 |
71 |
135 |
전지현 |
196 |
198 |
394 |
100 |
98 |
198 |
|
|
0 |
96 |
100 |
196 |
이영애 |
295 |
298 |
593 |
96 |
98 |
194 |
99 |
100 |
199 |
100 |
100 |
200 |
도움 좀 주세요
|