Teradata : Transpose columns to rows
Scenario - Need to convert columns in a table to rows
Source table Query :
select * from <table>\n
\n\nAnswer set :
\n\nJOB1 | JOB2 |
161 | 38 |
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:
\n\nCol1 Col2\n\nJOB1 161\nJOB2 38\n
\n\n
Solution:
if you need to get the column names as values you need to write them as literals:
SELECT 'Job1', job1 FROM TABLE\nUNION ALL \nSELECT 'Job2', job2 FROM TABLE\n
nVector
posted onEnjoy 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
Post Comment