I'm attempting to create a query to transpose rows into columns using the PIVOT function. I have a table in this form (this is just the partial view, the table contains more than 30 columns).
ID SUBJECT GRADE
000442 WRI001 C-
000442 PHY104 C
000442 MTH111 B
000442 MTH111 W
000442 MTH111 W
000442 PHY104 W
Expected result:
ID 'WRI001' 'MTH111' 'PHY104'
000442 C- B,W,W C,W
Query used:
select * from (
select ID,
SUBJECT,GRADE
from SECOND_YEAR_COMP
)
pivot
(
MAX(GRADE)
for SUBJECT in
('MTH111',
'WRI001',
'PHY104')
);
Query Output:
ID 'WRI001' 'MTH111' 'PHY104'
000442 C- W W
I know because of MAX(GRADE) I am getting single grade for each subject. Is there any way to get all the grades for the subject (as my expected result give above).