Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Rows to columns with MAX(DECODE)

metalrayMar 8 2011 — edited Mar 8 2011
Hi Guys,
I got a problem when transposing my rows to columns again.

this select gets me the unique combination of a translation in 3 languages.
what makes it unique is the combination of table_id, table_name,column_name.

select TABLE_ID,TABLE_NAME, COLUMN_NAME,Lang,Trans_TEXT from T_translations where TABLE_NAME='table1' and COLUMN_NAME ='column1' and Table_id='231441';

gives me three rows with the same table_id_table_name and column_name, what differs is the language each time and the text.

I guess the unique-making columns also have to be in the partition by cause:


SELECT TABLE_PK1,
MAX(DECODE ( rn , 1, Trans_TEXT)) English,
MAX(DECODE ( rn , 2, Trans_TEXT)) Chinese,
MAX(DECODE ( rn , 3, Trans_TEXT)) Russian
FROM
(SELECT TABLE_ID,Table_Name,Column_Name Trans_TEXT,
row_number() OVER ( partition by TABLE_ID,Table_Name,Column_Name order by rownum) rn
FROM T_translations where Trans_TEXT is not null)
group by TABLE_id,Table_Name,Column_Name


The problem is that everything comes out scrabled. all the translated text is mixed up. English text
is in column Chinese and Russian is in,.... I cant see a logic.

Does someone have an idea?
This post has been answered by Peter Gjelstrup on Mar 8 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 5 2011
Added on Mar 8 2011
2 comments
8,454 views