Rows to columns with MAX(DECODE)
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?