Quantcast
Channel: Teradata Forums - Database
Viewing all articles
Browse latest Browse all 14773

SQL to transpose (row to column) any level (nth level) of data - forum topic by Koushik Chandra

$
0
0

Hi,
I have a data like below:

Tgt

Src

lvl

L3_Tab1.Col1

L2_Tab1.Col3

0

L3_Tab1.Col2

L2_Tab2.Col2

0

L3_Tab1.Col3

L2_Tab2.Col3

0

L3_Tab1.Col4

L2_Tab2.Col1

0

L2_Tab1.Col3

L1_Tab3.Col1

1

L2_Tab1.Col3

L1_Tab1.Col1

1

L2_Tab2.Col1

L1_Tab2.Col1

1

L2_Tab2.Col2

L1_Tab2.Col2

1

L2_Tab2.Col2

L1_Tab1.Col2

1

L2_Tab2.Col2

L1_Tab3.Col2

1

L2_Tab2.Col3

L1_Tab3.Col3

1

Which I want to transpose and see the result like below:

Tgt

Src

lvl_1

L3_Tab1.Col1

L2_Tab1.Col3

L1_Tab3.Col1

L3_Tab1.Col1

L2_Tab1.Col3

L1_Tab1.Col1

L3_Tab1.Col2

L2_Tab2.Col2

L1_Tab2.Col2

L3_Tab1.Col2

L2_Tab2.Col2

L1_Tab1.Col2

L3_Tab1.Col2

L2_Tab2.Col2

L1_Tab3.Col2

L3_Tab1.Col3

L2_Tab2.Col3

L1_Tab3.Col3

L3_Tab1.Col4

L2_Tab2.Col1

L1_Tab2.Col1

Now in this case there is only one level but in practical there can be multiple levels.
So the requirement is to transpose (row to column) any level (nth level) of data.
Please suggest
Regards,
Koushik

Forums: 

Viewing all articles
Browse latest Browse all 14773

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>