Transpose rows to column

General
Enthusiast

Transpose rows to column

Hi,

 

I need a solution to transpose rows into columns in a teradata table. I have sample input data like these:

 

IDNameSubjectMarks
1SachinPhysics90
2AnilPhysics80
3VimalPhysics85
1SachinChemistry80
2AnilChemistry85
3VimalChemistry86
1SachinMaths80
2AnilMaths85
3VimalMaths90

 

And I want my output data to be like below:

 

IDNamePhysicsChemistryMaths
1Sachin908080
2Anil808585
3Vimal8586

90

 

How can I achieve this?

Thanks in advance.

3 REPLIES
Junior Contributor

Re: Transpose rows to column

TD16 added PIVOT, if you're on an earlier release the manual entry for PIVOT also shows how to get the same result using MAX(CASE)

Enthusiast

Re: Transpose rows to column

Thanks for the reply.. Can you please show me one example using CASE?

Junior Contributor

Re: Transpose rows to column

Seems like the HTML-manuals are screwed up, clicking the Example link leads to UDT Expressions :-) 

Try this direct link  (or look at the PDF manuals)