Transpose rows to columns

Database
Teradata Employee

Re: Transpose rows to columns

try,

select id, name,   

max(case when subjkect ='Maths' then msk else null end),

 max(case when subjkect ='Science' then msk else null end),

 max(case when subjkect ='english' then msk else null end)

from table

group by 1,2

Re: Transpose rows to columns

I'm having a Table called Test_Pivot which looks like

ID   VALUE  MONTH

1    5          201501

1    10        201501

1    10        201502

The output should look like this:

ID  201591 201502

----------------------

1    10        10

showing the Maximum of each month.

Any Ideas ?

Regards

Yorkie

Enthusiast

Re: Transpose rows to columns

HI Mlachlan,

please try this one.

sel 01 as  id,

( sel max(val)  from tab where mnth=201501 and id=01 group  by id,mnth)   as "201501",

( sel max(val)  from tab where mnth=201502 and id=01 group  by id,mnth)   as "201502",

 ( sel max(val)  from tab where mnth=201503 and id=01 group  by id,mnth)   as "201503"

from tab

group by 1,2,3,4

New Member

Re: Transpose rows to columns - New question

Hello All,

 

I have seen all the replys of the for Transpos rows to columns - My requirement is little different, Request  your help if any one

 

I have data in the database in the below way.  I have zeros in the data base but I dont want it on the Result but the columsn should be transposed.

 

IDFirst NameLast NameResq NumA1B1A2B2A3B3A4B4A5B5
111AC10 22.5 25 32.5 45 65.5 56 63.5 85 62.51022.52532.54565.55663.58562.5
112BE126100.00126100.0000.0000.0000.0000.00
113CF10 25.2 25 65 54 56.51025.225655456.500.0000.00

 

I wanted the Result in this way.

Result
IDFirst NameLast NameResq NumInd1Val1Ind2Val2
111AC10 22.5 25 32.5 45 65.5 56 63.5 85 62.5A110B122.5
111AC10 22.5 25 32.5 45 65.5 56 63.5 85 62.5A225B232.5
111AC10 22.5 25 32.5 45 65.5 56 63.5 85 62.5A345B365.5
111AC10 22.5 25 32.5 45 65.5 56 63.5 85 62.5A456B463.5
111AC10 22.5 25 32.5 45 65.5 56 63.5 85 62.5A585B562.5
112BE126100.00A1126B1100.00
113CF10 25.2 25 65 54 56.5A110B125.2
113CF10 25.2 25 65 54 56.5A225B265
113CF10 25.2 25 65 54 56.5A354B356.5

 

Reuest to please help.>!

 

Thanks in Advance

 

:) Have a nice day.