Teradata : Transpose columns to rows

Scenario - Need to convert columns in a table to rows

Source table Query :

select * from <table>

Answer set :

JOB1JOB2
16138


We need to transform the above answer set as below. We need to get the column name entry in each row with their corresponding values as shown below:

Col1    Col2

JOB1    161
JOB2    38


Solution:

if you need to get the column names as values you need to write them as literals:

SELECT 'Job1', job1 FROM TABLE
UNION ALL 
SELECT 'Job2', job2 FROM TABLE

nVector

posted on 21 Jun 18

Enjoy great content like this and a lot more !

Signup for a free account to write a post / comment / upvote posts. Its simple and takes less than 5 seconds